我尝试使用ElementTree检索信息。我成功地检索了许多属性,但处理过程可能因为缺少信息而停止。它会显示以下错误消息:
xml.etree.ElementTree.ParseError: no element found: line 1, column 0下面是我使用的代码:
import xml.etree.ElementTree
MyosmID = str(id_cinema)
r = requests.get("https://www.openstreetmap.org/api/0.6/node/"+MyosmID)
root = xml.etree.ElementTree.fromstring(r.content)
for child in root.iter('tag'):
if child.attrib['k'] == 'website':
website = child.attrib['v']
if child.attrib['k'] == 'wikidata':
wikidata = child.attrib['v']如何解决此错误情况?
发布于 2021-10-29 15:45:57
我将此代码添加到我的代码中,问题就解决了:
MyosmID = str(id_cinema)
try :
r = requests.get("https://www.openstreetmap.org/api/0.6/node/"+MyosmID)
r.raise_for_status()
root = xml.etree.ElementTree.fromstring(r.content)
fromstring: print(r.status_code)
for child in root.iter('tag'):
if child.attrib['k'] == 'website':
website = child.attrib['v']
if child.attrib['k'] == 'wikidata':
wikidata = child.attrib['v']
except Exception:
pass 感谢您的帮助:)
https://stackoverflow.com/questions/69771132
复制相似问题