Beautiful Soup 4 find_all não encontra links que Beautiful Soup 3 encontra
Eu notei um bug muito chato: BeautifulSoup4 (pacote:bs4
) geralmente encontra menos tags que a versão anterior (pacote:BeautifulSoup
).
Aqui está uma instância reproduzível desse problema:
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')))
Saída:
With BeautifulSoup 4 : 557
With BeautifulSoup 3 : 1701
A diferença não é menor, como você pode ver.
Aqui estão as versões exatas dos módulos, caso alguém esteja se perguntando:
In [20]: bs4.__version__
Out[20]: '4.2.1'
In [21]: BeautifulSoup.__version__
Out[21]: '3.2.1'