from bs4 import BeautifulSoup
import requests
HOST = "
https://www.anekdot.ru"
URL = "
https://www.anekdot.ru/release/anekdot/year/"
HEADERS = {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36 OPR/85.0.4341.72 (Edition Yx GX)"
}
def get_html(url, params=""):
r = requests.get(url, headers=HEADERS, params=params)
return r
def get_content(html):
soup = BeautifulSoup(html, "html.parser")
items = soup.find_all("div", class_="topicbox")
cards = []
for item in items:
cards.append(
{
"title": item.find("div", class_="text").get_text()
}
)
return cards
html = get_html(URL)
print(get_content(html.text))