【发布时间】:2020-08-09 18:14:32
【问题描述】:
我正在使用以下代码抓取 youtube 搜索结果:
import requests
from bs4 import BeautifulSoup
url = "https://www.youtube.com/results?search_query=python"
response = requests.get(url)
soup = BeautifulSoup(response.content,'html.parser')
for each in soup.find_all("a", class_="yt-simple-endpoint style-scope ytd-video-renderer"):
print(each.get('href'))
但它什么也没返回。这段代码有什么问题?
【问题讨论】:
-
不请求该站点上的 BeautifulSoup 进程 JavaScript。您将需要一个不同的解决方案,您不仅要下载基本 html,还要执行 javascripts 并等待动态内容。你可以从 Selenium 开始,或者从 scrapy-splash 开始scrapy
-
涉及javascript,美汤不执行。您必须使用
selenium之类的东西从 youtube 中提取数据。相反,请查看youtube-dl从 youtube 搜索/提取/下载数据。
标签: python beautifulsoup