python-3.x - 使用汤 python 在 html 页面中查找 aria-label
问题描述
我有 html 页面,使用以下代码:
<span itemprop="title" data-andiallelmwithtext="15" aria-current="page" aria-label="you in page
number 452">page 452</span>
我想找到 aria-label,所以我试过这个:
is_452 = soup.find("span", {"aria-label": "you in page number 452"})
print(is_452)
我想得到结果:
is_452 =page 452
我得到了结果:
is_452=none
怎么做 ?
解决方案
它有换行符,因此它与文本不匹配。尝试以下
from simplified_scrapy.simplified_doc import SimplifiedDoc
html='''<span itemprop="title" data-andiallelmwithtext="15" aria-current="page" aria-label="you in page
number 452">page 452</span>'''
doc = SimplifiedDoc(html)
is_452 = doc.getElementByReg('aria-label="you in page[\s]*number 452"',tag="span")
print (is_452.text)
推荐阅读
- ruby-on-rails - 允许用户在一个表单中选择多个列表
- weka - Weka 不离散最后一列
- r - 导入 .CSV 分组并查找四分位数/IQR
- azure - Azure 活动日志列表 API 未返回运行状况事件
- python - 使用 Python 3 和 Cython 0.25-2 使用 Buildozer 编译 Kivy
- docker - Docker:安装卷时,Jupyter 在 Web 界面中隐藏路径
- excel - 另存为 csv - 每小时
- python - 单选按钮变量不更新
- python - 如何从 Python 连接到 Netezza 数据库?
- angular - 动态渲染的 mat-expansion-panel 未按预期工作