如何抓取标题? [英] How to webscrape a title?
本文介绍了如何抓取标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何抓取 youtube 播放列表中第一个视频的标题?
I was wondering how to webscrape the title of the first video in an youtube-playlist ?
到目前为止我尝试过的:
what I have so far try'd:
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"}))
但它只打印 = "[]" 作为输出.我在这里做错了吗?
But it only prints = "[]" as output. Am I doing something wrong here ?
问候
推荐答案
我做了以下事情:
all = (soup.findAll("span",{"class":"title"}))
for a in all:
print(a.text)
break
当我查看汤时,我可以看到播放列表对于列表中的每首歌曲都有class=title
.输出为:
When I looked in the soup, I could see the playlist has class=title
for each song in the list. The output is:
Ed Sheeran - Thinking Out Loud [Official Video]
这篇关于如何抓取标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文