【问题标题】:BeautifulSoup find_all limited to 50 results?BeautifulSoup find_all 仅限于 50 个结果?
【发布时间】:2017-07-17 20:09:45
【问题描述】:

我正在尝试使用 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,但没有一个返回超过 50 个结果。有什么建议吗?

谢谢

【问题讨论】:

    标签: python beautifulsoup lxml html5lib


    【解决方案1】:

    尝试使用css-selector 查询。

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

    【讨论】:

      【解决方案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
      

      【讨论】:

        【解决方案3】:

        这一行只找到 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)
        

        【讨论】:

          最近更新 更多