Answer the question
In order to leave comments, you need to log in
How to concatenate python dictionaries?
import requests
from bs4 import BeautifulSoup
url = 'https://ria.ru/location_Novosibirsk/'
page = requests.get(url)
print(page.status_code)
news = []
data = []
clear_news = []
soup = BeautifulSoup(page.text,'html.parser')
news = soup.find_all('a', class_='list-item__title color-font-hover-only')
data = soup.find_all('div', class_='list-item__date')
for key in news:
clear_news.append(key.string)
for value in data:
clear_news.append(value.string)
print(clear_news)
Answer the question
In order to leave comments, you need to log in
You don't have dictionaries, you have lists.
news = soup.find_all('a', class_='list-item__title color-font-hover-only')
data = soup.find_all('div', class_='list-item__date')
keys = [item.string for item in news]
values = [item.string for item in data]
clear_news = dict(zip(keys, values))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question