2017-02-27 1 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

완벽한, 감사합니다! – 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 개의 일치 항목이 표시됩니다.

높이가있는 행을 찾으려면 해당 행을 편집해야합니다. 높이 : 18px; 스타일 (및 다른 값). 당신은 documentations에 따라 스타일의 인수로 정규 표현식을 전달할 수 있습니다,이 같은 아마 뭔가 :

soup.find_all('tr', style = re.compile('height:18px'), limit=None) 
관련 문제