你好,我正在练习我的请求和网络抓取技巧,所以我试图抓取 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)
和它的返回 [],我不明白为什么它在源代码中返回 [],
最佳答案
打印变量 html.content
的内容 - 它是否包含该 ID?
我敢打赌,youtube.com 是一个严重依赖 javascript 的网站,但 requests
模块没有 js 引擎。你的浏览器看到的通常不是像 requests
这样的模块看到的。
关于Python:Beautifulsoup 返回 None 或 [ ],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53980890/