Aug-21-2018, 04:59 PM
GPX files use XML namespaces.
Then can use lxml
Then can use lxml
from lxml import etree NSMAP = {"gpx": "http://www.topografix.com/GPX/1/1"} tree = etree.parse("input.gpx") for elem in tree.findall("gpx:trk", namespaces=NSMAP): print(elem)
Output:<Element {http://www.topografix.com/GPX/1/1}trk at 0x4e469e0>
<Element {http://www.topografix.com/GPX/1/1}trk at 0x4e469b8>
<Element {http://www.topografix.com/GPX/1/1}trk at 0x4e46990>
<Element {http://www.topografix.com/GPX/1/1}trk at 0x4e46968>
....
Try to get something out.>>> elem <Element {http://www.topografix.com/GPX/1/1}trk at 0x4e73760> >>> elem[0].tag '{http://www.topografix.com/GPX/1/1}name' >>> elem[0].text 'Viroflay - Vélizy - Arcueil'Can also search PyPi for gpx parser.