Python 网络垃圾Youtube页面

Python 网络垃圾Youtube页面,python,html,python-3.x,web-scraping,youtube,Python,Html,Python 3.x,Web Scraping,Youtube,我正试图通过一个链接从网上抓取一个youtube频道名称。但我得到了错误代码: title = response.find_all('div', class_= "style-scope ytd-channel-name") AttributeError: 'Response' object has no attribute 'find_all' 链接至网站: 代码: 谢谢大家! 以下代码返回div: url = "https://www.youtube.com/

我正试图通过一个链接从网上抓取一个youtube频道名称。但我得到了错误代码:

title = response.find_all('div', class_= "style-scope ytd-channel-name")
AttributeError: 'Response' object has no attribute 'find_all'
链接至网站:

代码:


谢谢大家!

以下代码返回div:

url = "https://www.youtube.com/channel/UCHOgE8XeaCjlgvH0t01fVZg"
req = requests.get(url)
soup = BeautifulSoup(req.text, "html.parser")
print(soup.div)
返回的值可以通过“soup.”值(例如soup.title)进行更改

我链接到文档,因为我认为您也可以查看以下内容: 我们可以用这个

from requests_html import HTMLSession
from bs4 import BeautifulSoup as bs # importing BeautifulSoup


video_url = "https://www.youtube.com/channel/UCHOgE8XeaCjlgvH0t01fVZg"
# init an HTML Session
session = HTMLSession()
# get the html content
response = session.get(video_url)
# execute Java-script
response.html.render(sleep=1)
# create bs object to parse HTML
soup = bs(response.html.html, "html.parser")
name = soup.find('yt-formatted-string', class_='style-scope ytd-channel-name')
print(name.text)
输出:-

TheTekkitRealm

你知道这个错误是什么意思吗?不,我一开始以为它意味着在类中找不到任何元素。但是在测试其他人的代码时,我得到了与attributeI相同的错误,这意味着对于调用它的对象,该方法不存在。变量响应没有find_all方法,这会在调用时导致错误。那么解决办法是什么呢?我认为BeautifulSoup能够找到具有特定类别的所有元素。如果答案有帮助,请按照答案进行投票和/或标记。如果没有,我很乐意修复。这不是问题的答案。更像是一个建议。在我看来,这也行不通。大部分YT数据由js呈现。BeautifulSoup将无法工作。
TheTekkitRealm