xml.etree.ElementTree returns 对象地址而不是值

xml.etree.ElementTree returns Object adress instead of Value

我正在尝试使用 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>

搜索到url-第4行请求内容为False:

<vmix>
  <version>24.0.0.51</version>
  <edition>Trial</edition>
  <recording>False</recording>
</vmix>

P.S。 print(root.findall('recording').text) 也不起作用:

AttributeError: 'list' object has no attribute 'text'attribute text is not 

findall() returns 一个列表,因此您需要在列表中迭代以访问文本属性

您还可以使用 find(),它 returns 找到第一个 'recording' 元素

for records in root.findall('recording'):
   print(r.text)

//or

print(root.find('recording').text)