美丽的汤错误:' nontype'对象没有属性' find_all'
我遇到此错误:
---> 14 content = s.find_all('p')
AttributeError: 'NoneType' object has no attribute 'find_all'
在下面运行脚本时:
r = requests.get('https://www.marketsandmarkets.com/Market-Reports/rocket-missile-market-203298804.html/')
soup = BeautifulSoup(r.content, 'html.parser')
s = soup.find('div', class_='entry-content')
content = s.find_all('p')
print(content)
它适用于某些URL,但是对于其他URL,它给出了属性错误。不知道为什么会发生这种情况。
I am getting this error:
---> 14 content = s.find_all('p')
AttributeError: 'NoneType' object has no attribute 'find_all'
While running the script below:
r = requests.get('https://www.marketsandmarkets.com/Market-Reports/rocket-missile-market-203298804.html/')
soup = BeautifulSoup(r.content, 'html.parser')
s = soup.find('div', class_='entry-content')
content = s.find_all('p')
print(content)
It's working for some URLs, but for other URLs it gives an attribute error. Not sure why this is happening.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当
soup.find
找不到任何东西时,它将返回无
。在中拨打s.find_all
如果S:或not none:
。因此,您的代码变为:
或也许:
https://crummy.com/software /BeautifulSoup/bs4/doc/#查找
When
soup.find
does not find anything, it returnsNone
. Guard yours.find_all
call withif s:
orif s in not None:
.So your code becomes:
or maybe:
Ref: https://crummy.com/software/BeautifulSoup/bs4/doc/#find