【发布时间】:2021-12-02 21:09:14
【问题描述】:
我正在尝试获取给定链接的 youtube 视频的标题。
但我无法访问包含标题的元素。我正在使用 bs4 来解析 html。 我注意到我无法访问 youtube 页面中“ytd-app”标签中的任何元素。
import bs4
import requests
listed_url = "https://www.youtube.com/watch?v=9IfT8KXX_9c&list=PLQVvvaa0QuDfKTOs3Keq_kaG2P55YRn5v&index=31"
listed = requests.get(listed_url)
soup = bs4.BeautifulSoup(listed.text, "html.parser")
a = soup.find_all(attrs={"class": "style-scope ytd-video-primary-info-renderer"})
print(a)
那么我怎样才能获得视频标题?是我做错了什么还是 youtube 故意创建了这样的标签来防止 web_scraping ?
【问题讨论】:
-
您可以使用 youtube_dl 来解析 youtube 视频
标签: python web-scraping beautifulsoup