Я просматриваю веб-сайт газеты Chicago Tribune, чтобы узнать дату новостных статей, но я не могу ее получить.
import time
import requests
from bs4 import BeautifulSoup
from bs4.element import Tag
url = 'https://www.chicagotribune.com/search/dispatcher.front?page={}&sortby=display_time%20descending&target=stories&spell=on&Query=cybersecurity#trb_search'
pages = 10
for page in range(1, pages+1):
res = requests.get(url.format(page))
soup = BeautifulSoup(res.text,"lxml")
for item in soup.find_all("a", {"class": "trb_search_result_title"}, href=True):
_href = item.get("href")
try:
resp = requests.get(_href)
except Exception as e:
try:
resp = requests.get("https://www.chicagotribune.com"+_href)
except Exception as e:
continue
sauce = BeautifulSoup(resp.text,"lxml")
timetag = sauce.find('time',{'class': "trb_search_result_datetime"})
date = None
if isinstance(timetag, Tag):
timetag = timetag.get_text().strip()
print(f'{date}\n')
time.sleep(3)
Почему я не получаю никаких результатов.
Спасибозаранее.