Geo*_*Jor 0 python beautifulsoup
这是我的代码,使用find_all,但它适用于.find():
import requests
from BeautifulSoup import BeautifulSoup
r = requests.get(URL_DEFINED)
print r.status_code
soup = BeautifulSoup(r.text)
print soup.find_all('ul')
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
Traceback (most recent call last):
File "scraper.py", line 19, in <module>
print soup.find_all('ul')
TypeError: 'NoneType' object is not callable
Run Code Online (Sandbox Code Playgroud)
看起来你正在使用BeautifulSoup版本3,它使用了略微不同的命名约定,例如:.findAll,而BeautifulSoup 4标准化命名更像PEP8,例如:( .find_all但保留较旧的命名以实现向后兼容).注意,soup('ul')这相当于在两者上找到所有.
要下载并安装,请使用pip install beautifulsoup4.
然后将导入更改为:
from bs4 import BeautifulSoup
Run Code Online (Sandbox Code Playgroud)
然后你很高兴去.