web-scraping - BeautifulSoup 在使用 .find 方法时找不到所有标签?
问题描述
我正在尝试从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。
解决方案
尝试这个:
repo = soup.find_all("article",{"class":"Box-row"})
推荐阅读
- regex - 当文本字段只有空格时如何保持无效
- java - 在 SpringMVC 的上下文中,如何让 Web 服务为同一个类提供不同的 JSON 表示?
- python - 以快速方式将 pandas 列乘以年度系数
- android - Android 发送 ArrayList 对象
- php - 为什么 Laravel 5 邮件,我附加了一个 .tmp 文件?
- arrays - mongodb: query to check if item in an array contains a particular string
- python - PCAP 未通过 Python API 调用以正确的格式下载
- python - 在 python 中从多进程迁移到 MPI
- node.js - express-validator 错误-> TypeError: req.checkBody 不是函数
- ruby-on-rails - Wicked PDF gem 在本地工作,但在部署时显示不同的字体