我正在尝试解析XML,但在尝试从响应中提取链接时遇到了问题。
我的XML看起来像:
Polymer({
is: "folleto-digital",
properties: {
idf: String,
len: String
},
observers: ['_sendRequest(idf, len)'],
_sendRequest: function(idf, len) {
if (idf && len) {
this.$.ajax.generateRequest();
}
}
});
我的功能:
<properties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" lastUpdate="2016-11-23">
<property myId="3" lastUpdate="2016-11-20T01:25:17+01:00" xlink:href="http://example.com/webservice/rest/1/properties/3"/>
<property myId="10" lastUpdate="2016-11-16T03:52:54+01:00" xlink:href="http://example.com/webservice/rest/1/properties/10"/>
...
我可以在尝试获取网址时提取 r = requests.get(url, auth=(self.usr, self.psw))
xml = r.content
root = ET.fromstring(xml)
for prop in root:
m_id= prop.attrib['myId']
my_url = prop.attrib['xlink:href']
属性,但我收到错误