python-3.x - 如何从 bs4.element.Tag 中获取值
问题描述
我正在与BeautifulSoup
一个网络抓取项目合作。我有一个标签:
<span class="sal "><em class="iconRup"></em>40.0 Lacs</span>
我想从中检索40.0 Lacs
。
我尝试使用:
salary = soup.find('span', class_ = 'sal')
print(salary.string())
但这给出了一个None object
. 我该如何进行?
解决方案
这是如何:
from bs4 import BeautifulSoup
html = """
<span class="sal "><em class="iconRup"></em>40.0 Lacs</span>
"""
soup = BeautifulSoup(html, "html.parser").find('span', class_='sal')
print(soup.getText())
输出:
40.0 Lacs
推荐阅读
- python - 在 Python 中选择要替换的元素
- python - 如何查看python模块的源码,如sys、os、request模块?
- android - 不在后台检索 GPS
- javascript - ReferenceError:没有为上下文定义 React
- docker - 如何使用标准输入中的 dockerfile 和 shell 变量来构建 docker 映像
- python-3.x - 逼真的 3D 形状动态渲染
- python - for 循环不能正常工作?
- javascript - 替换多级Javascript数组中特定键的字符串
- python - 如何在 Python 中的单个 HTTP POST 请求中格式化多个数据?
- javascript - 在 Django 项目中实现 Ajax 无法正常工作