atom\xml python feedparser <content> enenclosed Access



如何访问'内容'封闭与feedparser?

<content type="application/xml">
<m:properties xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<d:Ref_Key>3a496b6e</d:Ref_Key
</m:properties>
</content>

访问"content"的代码

d = feedparser.parse("http://localhos/odata/standard.odata/Document_Order")
d.entries[0].content[0]

返回类似

的内容
{'base': u'http://localhos/odata/standard.odata/Document_Order', 'type': u'application/xml', 'value': u'', 'language': None}

那么如何获得'm:properties'和'd:Ref_Key'呢?

似乎feedparser不能解析非XML标签,建议使用XML .etree. elementtree

import requests
import xml.etree.ElementTree
url = http://localhost/standard.odata/Document_Visit
req = requests.get(self.url, auth=(self.login, self.password))
root = etree.fromstring(req.text.encode('utf-8'))
entrys = root.findall('{http://www.w3.org/2005/Atom}entry')
properties = content.findall('{http://schemas.microsoft.com/ado/2007/08/dataservices/metadata}properties')
prop_dict = dict()
for prop in properties[0]:
   pritn prop                   

最新更新