【发布时间】:2019-05-30 23:50:48
【问题描述】:
我正在尝试使用 Beautiful Soup 获取 YouTube 上第一个视频搜索的锚标记的 href。我正在使用“a”和 class_="yt-simple-endpoint style-scope ytd-video-renderer" 来搜索它。 但我得到无输出:
from bs4 import BeautifulSoup
import requests
source = requests.get("https://www.youtube.com/results?search_query=MP+election+results+2018%3A+BJP+minister+blames+conspiracy+as+reason+while+losing").text
soup = BeautifulSoup(source,'lxml')
# print(soup2.prettify())
a =soup.findAll("a", class_="yt-simple-endpoint style-scope ytd-video-renderer")
a_fin = soup.find("a", class_="compact-media-item-image")
#
print(a)
【问题讨论】:
-
您从
requests.get()获得的html 源代码中没有class="yt-simple-endpoint style-scope ytd-video-renderer"。这就是为什么你得到 None
标签: python-3.x python-2.7 beautifulsoup