python - 如何用 beautifulsoup 和 selenium 获得这个数字?
问题描述
嘿,我需要这个号码:
27
<a class="r8ZrO" href="/p/B99QGseomNG/comments/">
"View all "
<span>27</span>
" comments"
driver.get(each)
soup = BeautifulSoup(driver.page_source, "html.parser")
ncomments = soup.find('a', {'class': 'r8ZrO'}).text
当然这不起作用,因为该数字不在给定的班级中。
那么如何获取类里面的内容呢?
这是我的输出:
<a class="r8ZrO" href="/p/B99Ql4cl6MO/comments/">View all <span>4</span> comments</a>
解决方案
从 bs4 导入 BeautifulSoup
html="""<a class="r8ZrO" href="/p/B99QGseomNG/comments/">
"View all "
<span>27</span>
" comments"""
汤 = BeautifulSoup(html,'lxml')
ncomments = soup.find('a', class_='r8ZrO').span.text
推荐阅读
- excel - 使用带有 VBA 的表格从另一个工作表复制和粘贴
- python - 在 python 3.6.8 中使用正则表达式的语法无效
- java - 每当我注销时应用程序崩溃,使用firebase进行身份验证
- git - Jenkins-trigger- BitBucket webhook 网络错误问题
- node.js - 返回 api rest with node
- msal.js - 是否建议在 MSAL 中将 loginPopup 或 acquireTokenPopup 用于 Web 应用程序?
- node.js - 护照认证和登录重定向
- apache-spark - 在 Spark Streaming 上使用 HiBench 基准测试时如何设置 blockInterval?
- r - 如何使用ggplot2绘制与排序点叠加的箱线图
- python - 在 AWS Lambda Python 中导航事件