BeautifulSoup find_all 限制为 50 个结果?

BeautifulSoup find_all limited to 50 results?

我正在尝试使用 BeautifulSoup 从页面获取结果:

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,但其中 none return 超过 50 个结果。有什么建议吗?

谢谢

尝试使用 css-selector 查询。

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

>>>613

试试这个 -

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

这一行只查找行with 'height:18px;风格。

scores = soup.find_all('tr', {'style': 'height:18px;'}, limit=None)

如果您查看页面源代码并搜索 "height:18px;",您将看到 50 个匹配项。但是,如果您搜索不带引号的 height:18px;,您将看到 613 个匹配项。

您需要编辑该行以查找 具有 height:18px 的行;样式(和其他值)。 您可以根据 documentations 将正则表达式作为样式参数传递,也许是这样的:

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