python - Python - 如何从 bs4 输出中提取数字
问题描述
我正在尝试使用 BeautifulSoup 从网站上获取价格,到目前为止,我已经设法获得:
<h2>£<!-- -->199.99</h2>
我只想收到“199.99 英镑”有没有办法过滤掉这些字母?
提前致谢
解决方案
get_text
如有必要,您将使用带有 strip=True 的函数进行清理
from bs4 import BeautifulSoup
html = '<h2>£<!-- -->199.99</h2>'
soup = BeautifulSoup(html,'html5lib')
result = soup.find('h2').get_text(strip=True)
print(result)
#£199.99
推荐阅读
- reactjs - 登录成功反应redux时不重定向到HOC中传递的组件
- regex - 如何制作一个检查所有第一个字母都应该是大写的模式?
- python - 使用 Flask API,如何使用浏览器/客户端的 jwt_required 装饰器从服务器上传和下载文件?
- bash - tar 在磁盘已满时返回成功状态
- ios - iOS BLE 附件想在未查看应用时打开应用。如何使此警报静音?
- java - 如何使用 Apache Batik 库在 SVGGraphics2D 中转换 Graphics2D?
- linux - 卸载高分辨率定时器模块
- php - 如何使用 else 创建 SQL 和 PHP IF 语句
- c# - XML 矩形选项
- android - 如何计算天数以在android中获取结束日期?