【发布时间】:2021-03-23 15:01:38
【问题描述】:
我正在尝试使用 xml.etree.ElementTree 从 xml 中获取价值
from urllib.request import urlopen
import xml.etree.ElementTree as ET
with urlopen('http://127.0.0.1:8088/api/?') as f:
tree = ET.parse(f)
root = tree.getroot()
print(root.findall('recording'))
但我得到的是:
<Element 'recording' at 0x000001D871642E50>
第 4 行搜索到的 url-request 内容为 False:
<vmix>
<version>24.0.0.51</version>
<edition>Trial</edition>
<recording>False</recording>
</vmix>
附: print(root.findall('recording').text) 也不起作用:
AttributeError: 'list' object has no attribute 'text'attribute text is not
【问题讨论】:
标签: python xml python-requests xml-parsing elementtree