【发布时间】:2021-03-10 20:29:53
【问题描述】:
我正在尝试通过链接从网络上抓取 youtube 频道名称。但我得到错误代码:
title = response.find_all('div', class_= "style-scope ytd-channel-name")
AttributeError: 'Response' object has no attribute 'find_all'
网站链接:https://www.youtube.com/channel/UCHOgE8XeaCjlgvH0t01fVZg
代码:
url = 'https://www.youtube.com/channel/UCHOgE8XeaCjlgvH0t01fVZg'
response = requests.get(url)
title = response.find_all('div', class_= "style-scope ytd-channel-name")
soup = BeautifulSoup(title.text, 'lxml')
print(soup)
谢谢!
【问题讨论】:
-
你知道错误是什么意思吗?
-
不,我一开始以为这意味着它无法找到该类的任何元素。但是测试其他人的代码我得到了与属性相同的错误
-
这意味着该方法对于您从中调用它的对象不存在。变量response没有find_all方法,调用时会报错。
-
嗯好吧。但是解决方法是什么?我认为 BeautifulSoup 能够找到某个类的所有元素
-
如果答案有帮助,请点赞和/或标记为答案。如果没有,我很乐意解决。
标签: python html python-3.x web-scraping youtube