我一直在解析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,我得到相同的数据)
根据位于https://docs.python.org/2/library/xml.etree.elementtree.html#finding-interesting-elements的文档,
Element.find
返回带有特定标记的第一个子项。换句话说,它返回一个元素,而不是iterable,这意味着您不能使用for循环来访问它相关问题 更多 >
编程相关推荐