如何网络抓取标题?
How to webscrape a title?
我想知道如何在 youtube-playlist 中抓取第一个视频的标题?
我目前尝试过的:
import urllib.request
from bs4 import BeautifulSoup
theurl = "https://www.youtube.com/watch?v=lp-EO5I60KA&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj"
thepage = urllib.request.urlopen(theurl)
soup = BeautifulSoup(thepage, "html.parser")
print(soup.findAll("h1",{"class":"title style-scope ytd-video-primary-info-renderer"}))
但它只打印 = "[]" 作为输出。我是不是做错了什么?
问候
我做了以下事情:
all = (soup.findAll("span",{"class":"title"}))
for a in all:
print(a.text)
break
当我查看汤时,我可以看到 播放列表 列表中的每首歌曲都有 class=title
。输出为:
Ed Sheeran - Thinking Out Loud [Official Video]
我想知道如何在 youtube-playlist 中抓取第一个视频的标题?
我目前尝试过的:
import urllib.request
from bs4 import BeautifulSoup
theurl = "https://www.youtube.com/watch?v=lp-EO5I60KA&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj"
thepage = urllib.request.urlopen(theurl)
soup = BeautifulSoup(thepage, "html.parser")
print(soup.findAll("h1",{"class":"title style-scope ytd-video-primary-info-renderer"}))
但它只打印 = "[]" 作为输出。我是不是做错了什么?
问候
我做了以下事情:
all = (soup.findAll("span",{"class":"title"}))
for a in all:
print(a.text)
break
当我查看汤时,我可以看到 播放列表 列表中的每首歌曲都有 class=title
。输出为:
Ed Sheeran - Thinking Out Loud [Official Video]