如何用美丽的汤刮擦YouTube视频描述
我正在尝试网络刮擦YouTube视频列表,并且想收集每个视频的YouTube描述。但是,我没有成功,不明白为什么。任何帮助都非常感谢。 (有问题的YouTube视频: https:> https://www.youtube.com/watch? V = 57TJVV_PCXG& t = 55s )
element_titles = driver.find_elements_by_id("video-title")
result = requests.get(element_titles[1].get_attribute("href"))
soup = BeautifulSoup(result.content)
description = str(soup.find("div", {"class": "style-scope yt-formatted-string"}))
递减的结果为 none
注意 我知道存在YouTube API,但是您必须为API键付费,这不是我的利益
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要提取描述,您可以同时使用硒或美丽的套件。后者更快,
如果您运行
print(sip.prettify())
并查找视频说明的一部分,则说明知道这只是我的, 这是代码。 ,您将看到完整的描述在一个大的JSON结构内部,特别是在
shortdescription之间包含了描述”:“
and”,“ isCrawlable
,因此我们可以使用Regex提取这两个字符串之间包含的子字符串。将两个字符串之间包含的每个字符(*
)找到每个字符的正则命令是(?< = ShortDescription“:”)。 >
To extract the description you can use both selenium or beautifulsoup. The latter is faster, here is the code
If you run
print(soup.prettify())
and look for a part of the video description, sayknow this is just my
, you will see that the complete description is inside a big json structureIn particular the description is included between
shortDescription":"
and","isCrawlable
, so we can use regex to extract the substring included between these two strings. The regex command to find every character (.*
) included between the two strings is(?<=shortDescription":").*(?=","isCrawlable)