简体   繁体   English

python findall()返回空列表

[英]python findall() returns empty list

I want to use Python to get open API data. 我想使用Python获取开放的API数据。 So, I parsed the URL to XML and tried to get the information I wanted through findall(). 因此,我将URL解析为XML,并尝试通过findall()获得所需的信息。

part of the data, 部分数据,

<safemap:CTPRVN_CD>11</safemap:CTPRVN_CD>
<safemap:SGG_CD>11500</safemap:SGG_CD>

i want this, 我要这个,

root.findall('safemap:ctprvn_cd')

but returned empty list. 但返回空列表。

XML is case-sensitive . XML 区分大小写 I believe that root.findall('safemap:CTPRVN_CD') might work better. 我相信root.findall('safemap:CTPRVN_CD')可能会更好。

Also I noticed that your xml seems to use namespaces . 我也注意到您的xml似乎使用名称空间 Usually there is a problem with namespaces, when working with xmls using lxml or xml package in python. 通常,在python中使用lxmlxml包处理xml时,名称空间存在问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM