【发布时间】:2020-03-06 18:37:16
【问题描述】:
我正在尝试从https://github.com/trending 中获取在 Python 中使用 BeautifulSoup 的趋势存储库的数量。该代码应该找到所有带有 class_ = "Box-row" 的标签,然后打印找到的数字。在该网站上,趋势存储库的实际数量为 25,但代码仅返回 9。
我尝试将解析器从“html.parser”更改为“lxml”,但都返回了相同的结果。
page = requests.get('https://github.com/trending')
soup = BeautifulSoup(page.text, 'html.parser')
soup = BeautifulSoup(page.text)
repo = soup.find(class_ = "Box-row")
print(len(repo))
在 html 中有 25 个带有“Box-row”类属性的标签,所以我希望看到 print(len(repo)) = 25,但实际上是 9。
【问题讨论】:
标签: web-scraping beautifulsoup