0

我有这个脚本:

infile = open("t.gpx", "r")
contents = infile.read()
soup = BeautifulSoup(contents, 'xml')

wpts = soup.find_all('wpt')
names = soup.find_all('name')
texts = soup.find_all('text')
types = soup.find_all('type')
gnames = soup.find_all('groundspeak:name')
gplaced = soup.find_all('groundspeak:placed_by')
print()
for i in range(0, len(wpts)):
    print(names[i].get_text(), end=' ')
    print(texts[i].get_text(), end=' ')
    print(types[i].get_text(), end=' ')
    print(gnames[i].get_text(), end=' ')
    print(gplaced[i].get_text(), end='\n')

并输入文件 t.gpx。

t.gpx

第一行输出:
XX022421 jn32766 Geocache|Geocache jn32766 jn_mapotic

可以,但第二行与我预期的不同。
jn32766 ss_old_687 Geocache ss_old_687 罗兹

我希望一开始是 XX027931。

我的脚本有什么问题?

4

0 回答 0