python - 如何获取html文档中字符的坐标?
问题描述
<span class = 'ocrx_word' id = 'word_1_45' title = 'bbox 369 429 301 123;x_wconf 96'>refrence</span>
如何使用 python 从上述代码中仅提取 369 429 301 123 值?
解决方案
解决这个问题的最简单方法是最有可能用分号分割文本以获取之前的所有内容。然后您可以再次拆分并仅保留数字部分。
from bs4 import BeautifulSoup
tag = "<span class = 'ocrx_word' id = 'word_1_45' title = 'bbox 369 429 301 123;x_wconf 96'>refrence</span>"
soup = BeautifulSoup(tag, 'html.parser')
s = soup.findAll('span')
for span in s:
print([x for x in span.attrs['title'].split(';')[0].split() if x.isdigit()])
推荐阅读
- java - 关于“可以从多个模块访问包 org.w3c.dom 的具体问题:
, java.xml" - python-3.x - 如何从 Robotframework 调用 python 脚本作为 Teardown 的一部分
- apache-spark - 如何使用 REST API 从 Spark 历史服务器获取查询执行计划?
- java - 为什么 permitAll() 返回 403 spring security?
- java - 使用 ManyToOne 关联查询导致 SQLException
- jquery - 如何使用 jquery 更改嵌套 span 的值?
- swiftui - Swiftui UIViewRepresentable 表格视图在滚动时具有填充
- javascript - 无法在 Quasar 应用程序的 Vue.js 组件上的“this.$attrs”上定义类型
- objective-c - 如何在Objective C中执行从小部件到父应用程序的深层链接
- elasticsearch - 弹性搜索结果不一致——查询多个分片