使用ElementTree解析XML数据(无或无数据)

2024-05-15 09:25:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在解析URL(API)中的XML数据。我从API获取数据,如果我从XML文件获取所有数据。此外,我还可以得到标记结果,但有一次,当我尝试以文本格式获取数据时,我没有得到任何结果或没有结果

这是我的密码:

import requests
import xml.etree.ElementTree as ET

url = 'http://vatbook.euroutepro.com/xml2.php?fir=LQSB'
response = requests.get(url)
bookings_data = response.text
root = ET.fromstring(bookings_data)

for atcs in root.iter('booking'):
   for callsign_tag in atcs.find("callsign"):
      print (callsign_tag.text)

现在,当我运行这段代码时,我什么都没有得到,我尝试了findall的一系列不同配置,但仍然没有结果(或者我没有得到结果)

这里可能出了什么问题

下面是一个XML文件的URL:http://vatbook.euroutepro.com/xml2.php?fir=LQSB (在这个URL中,您可以使用XML或XML2,我得到相同的数据)


Tags: 文件数据importcomapihttpurlxml