【发布时间】:2019-05-27 14:22:27
【问题描述】:
你好我正在练习我的请求和网络抓取技巧,所以我试图在 youtube 上抓取热门页面,并拉出热门视频的标题,即这个链接 youtube
这是我正在运行的代码
import requests
from bs4 import BeautifulSoup
url = 'https://www.youtube.com/feed/trending'
html = requests.get(url)
soup = BeautifulSoup(html.content, "html.parser")
a = soup.find_all("a", {"id": "video-title"})
print(a)
及其返回[],我不明白为什么它在源代码中返回[],
【问题讨论】:
-
正如以下所有答案中所述,内容是动态的,无法使用
requests检索。通常,我们可以对 JavaScript 代码进行逆向工程,但通常不值得,而且使用selenium更容易。
标签: python web web-scraping beautifulsoup python-requests