我注意到一个非常烦人的错误:BeautifulSoup4(包:) bs4经常找到比以前版本(包:)更少的标签BeautifulSoup.
这是该问题的可重现实例:
import requests
import bs4
import BeautifulSoup
r = requests.get('http://wordpress.org/download/release-archive/')
s4 = bs4.BeautifulSoup(r.text)
s3 = BeautifulSoup.BeautifulSoup(r.text)
print 'With BeautifulSoup 4 : {}'.format(len(s4.findAll('a')))
print 'With BeautifulSoup 3 : {}'.format(len(s3.findAll('a')))
Run Code Online (Sandbox Code Playgroud)
输出:
With BeautifulSoup 4 : 557
With BeautifulSoup 3 : 1701
Run Code Online (Sandbox Code Playgroud)
你可以看到,差异并不小.
以下是模块的确切版本,以防有人想知道:
In [20]: bs4.__version__
Out[20]: '4.2.1'
In [21]: BeautifulSoup.__version__
Out[21]: '3.2.1'
Run Code Online (Sandbox Code Playgroud)