2017-02-27 25 views
4

私はBeautifulSoupを使用してページから結果を取得しようとしている:BeautifulSoup find_allは50件に制限されていますか?

req_url = 'http://www.xscores.com/soccer/livescores/25-02' 
request = requests.get(req_url) 
content = request.content 
soup = BeautifulSoup(content, "html.parser") 
scores = soup.find_all('tr', {'style': 'height:18px;'}, limit=None) 
print(len(scores)) 
>50 

私はこの前のソリューション読み:Beautiful Soup findAll doen't find them all を、私はhtml.parser、lxmlのとhtml5libを試してみましたが、それらのどれもが50以上のものを返しません結果。助言がありますか?

答えて

1

css-selectorクエリを使用してみてください、ありがとうございました。

scores = soup.select('#scoretable > tr[style*="height:18px;"]') 
print(len(scores)) 

>>>613 
+0

パーフェクト: あなたはこのような何か多分、documentationsに応じてスタイルの引数として正規表現を渡すことができます! – StevenH

2

これを試してみてください -

req_url = 'http://www.xscores.com/soccer/livescores/25-02' 
request = requests.get(req_url) 
html=request.text 
soup = BeautifulSoup(html, "html5lib") 
scoretable=soup.find('tbody',id='scoretable') 
scores=scoretable.find_all('tr') 
len(scores) 
>617 
1

この行だけ「高さを持つ行を見つける:18px;スタイル。

ページソースを参照して"height:18px;"を検索すると、50個の一致が表示されます。しかし、引用符なしでheight:18px;を検索すると、613件が表示されます。

にはの高さを持つ行を検索するには、その行を編集する必要があります。スタイル(および他の値)。ありがとう、

soup.find_all('tr', style = re.compile('height:18px'), limit=None) 
関連する問題