python - 用 BeautifulSoup 抓取网站 : TypeError: 'NoneType' object is not callable

标签 python web-scraping beautifulsoup

我是一个绝对的初学者。我尝试使用 BeautifulSoup 并抓取一个网站。我确实得到了 HTML,但我现在想得到所有具有 content_class 类的 div

这是我的尝试:

import requests
from BeautifulSoup import BeautifulSoup

#Request the page and parse the HTML
url = 'mywebsite'
response = requests.get(url)
html = response.content

#Beautiful Soup
soup = BeautifulSoup(html)
soup.find_all('div', class_="content_class")

但这不起作用。 我得到:

Traceback (most recent call last): File "scrape.py", line 11, in soup.find_all('div', class_="content_class") TypeError: 'NoneType' object is not callable

我做错了什么?

最佳答案

您正在使用 BeautifulSoup version three ,但似乎遵循 BeautifulSoup 的文档 version four . Element.find_all() method仅在最新的主要版本中可用(称为 Element.findAll() in version 3 )。

我强烈建议你升级:

pip install beautifulsoup4

from bs4 import BeautifulSoup

第 3 版已于 2012 年停止接收更新;它现在已经严重过时了。

关于python - 用 BeautifulSoup 抓取网站 : TypeError: 'NoneType' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44875219/

相关文章:

python - 期待 python 中的二维数组错误

python - 为什么在使用 multipart/form-data 时不能正确发送带有 Unicode 的 POST 名称?

用于大型 HTML/XML 的 Python 模板

Python、Selenium、BS4 - 导航到下一页

python - 如何使用 BeautifulSoup 模拟 ":contains"?

python - 如何使用 beautiful soup 获取 <ol> 的第一行并将其设为 JSON 键,而以下其余部分是列表的值?

python - 使用 Azure 资源管理器 REST API

xpath - 碎片 : Select tag with non-breaking space with xpath

python - 如何使用 re.compile 和 re.findall 删除括号内的文本?

python - 我正在尝试代码,但不知道我在某个页面上遇到错误,例如没有对象属性