【发布时间】:2021-05-04 12:19:44
【问题描述】:
我想写一个从 YouTube 音乐播放列表中收集视频标题的爬虫,因为有时视频会被删除。我是 python 新手。我通过一篇文章写了代码:
我检查了许多网站上的代码功能(通过更改链接、标签和类),一切正常,但不知何故,YouTube 却没有。
如何从播放列表中获取视频标题?
import requests
from bs4 import BeautifulSoup
url = 'https://www.youtube.com/playlist?list=PLuDh46ey2oy-qmIqPH0o1ZUZ9BFuqvtBn'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')
quotes = soup.find_all('a', class_='yt-simple-endpoint style-scope ytd-playlist-video-renderer')
for quote in quotes:
print(quote.text)
【问题讨论】:
标签: python web-scraping