Web抓取-find_all()返回空列表

时间:2020-02-10 03:31:07

标签: python beautifulsoup

我正在抓捕《纽约时报》的网站,以获取某个项目的数据,但我得到的只是空列表。

我已经尝试使用html.parser和lxml,但是没有一个有效。下面是我的代码:

#Step 1: Reading the web page into python
import requests

read_webpage = requests.get("https://www.youtube.com/redirect?v=zXif_9RVadI&event=video_description&q=https%3A%2F%2Fwww.nytimes.com%2Finteractive%2F2017%2F06%2F23%2Fopinion%2Ftrumps-lies.html&redir_token=UvU4IsVzgsy7oj0Ns0XLJx26f0l8MTU4MTM4NDUxM0AxNTgxMjk4MTEz")

from bs4 import BeautifulSoup as bs

soup = bs(read_webpage.content, "lxml")

results = soup.find_all('span', attrs={'class':'short-desc'})

print(len(results))

Output = 0

1 个答案:

答案 0 :(得分:-2)

现在工作正常,谢谢。我重新启动了内核