root = ET.fromstring(xml_string)
namespace = {'ns': 'http://ergast.com/mrd/1.4' }
for race in root.find('ns:RaceTable', namespace):
round_num = race.get("round")
circuit = race.find('ns:RaceName', namespace).text
date = race.find("ns:Date", namespace).text
time = race.find("ns:Time", namespace).text
print(round_num, circuit, date, time)
错误:
Element.findall() finds only elements with a tag which are direct children of the current element.
If the XML input has namespaces, tags and attributes with prefixes in the form prefix:sometag get expanded to {uri}sometag where the
prefix is replaced by the full URI. Also, if there is a default
namespace, that full URI gets prepended to all of the non-prefixed
tags.
Checkout this documentation https://docs.python.org/2/library/xml.etree.elementtree.html#parsing-xml-with-namespaces
错误:
你可以用这样的东西
相关问题 更多 >
编程相关推荐