我正试图从纽约时报头版 (www.nytimes.com) 上获取头条新闻。过程完成而不从soup.find_all函数打印文本(或任何东西)。我已经soup.find_all(class_="blancedHeadline")尝试过语法,将其从soup.find_all("span", {"class" : "blancedHeadline")甚至attrs=在类区别之前添加。这是我拥有的代码,在尝试弄清楚我做错了什么之后,我不知道是什么导致了问题:import requestsfrom bs4 import BeautifulSoupbase_url = 'https://www.nytimes.com/'r = requests.get(base_url)soup = BeautifulSoup(r.text, 'lxml')headline_text = soup.find_all('span', {'class':'balancedHeadline'})for headline in headline_text: print(headline)
添加回答
举报
0/150
提交
取消