Answer the question
In order to leave comments, you need to log in
I want to draw a joke from the site, but it gives an error, what am I doing wrong?
import requests
from bs4 import BeautifulSoup
def get_first_news():
headers = {
'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36 OPR/84.0.4316.52'
}
url = 'https://www.anekdot.ru/random/anekdot/'
r = requests.get(url=url, headers=headers)
soup = BeautifulSoup(r.text, 'lxml')
anecdot = soup.find_all('div', class_="topicbox")
for article in anecdot:
article_title = article.find('div', class_="text").text.strip()
print(f'{article_title}')
get_first_news()
Answer the question
In order to leave comments, you need to log in
import requests
from bs4 import BeautifulSoup
def get_first_news():
headers = {
'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36 OPR/84.0.4316.52'
}
url = 'https://www.anekdot.ru/random/anekdot/'
r = requests.get(url=url, headers=headers)
soup = BeautifulSoup(r.text, 'html.parser')
anecdot = soup.find_all('div', class_="text")
for article in anecdot:
article_title = article.text.strip()
print(article_title)
get_first_news()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question