我使用以下代码抓取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'))
但它什么也没有回报。这个代码有什么问题
BeatifulSoup不是Youtube刮片的合适工具-Youtube正在使用JavaScript生成大量内容
您可以轻松地测试它:
(请注意,您在屏幕截图上看到的链接不在列表中)
为此,您需要使用另一种解决方案-硒可能是一个不错的选择。请查看此线程以了解详细信息Fetch all href link using selenium in python
相关问题 更多 >
编程相关推荐