python-3.x - bsoup xml解析如何获取next_element结果的标签名?
问题描述
我有一个 xml,我得到的结果s.next_element
为
<string content="," height="10" hpos="235" style="bold" vpos="3129" width="4"></string>
现在我想要这个元素的标签,即string
. 我如何得到它?
s.next_element.tag
不管用。
解决方案
您可以使用.name
:
s.next_elemen.name
from bs4 import BeautifulSoup
soup = BeautifulSoup("""<string content="," height="10" hpos="235" style="bold" vpos="3129" width="4"></string>""", "html.parser")
print([x.name for x in soup]) # Output: ['string']
推荐阅读
- android - 我收到“循环依赖”Android Dagger Hilt 错误
- elasticsearch - Elasticsearch:函数分数 + 布尔查询,仅匹配具有某些可能值集中的术语的文档
- triggers - 气流限制每日触发
- sql - Oracle 在 DML 中调用函数
- android - Android - Facebook 登录 - 获取身份验证令牌
- html - 如何直观地比较两个 HTML 文档?
- python - 使用scrapy在csv中存储数据的问题
- c++ - Windows没有出现在codelite ide中
- export - 谷歌地球引擎 ... 将图像导出为 ascii
- c - 分段错误,创建套接字