我正在尝试解析:http://www.codespot.blogspot.in/atom.xml?redirect=false&start-index=1&max-results=500
问题是:
我必须将xml存储在一个文件中,以便ElementTree对其进行解析。如何避免它,只解析GET请求的字符串响应?
虽然我这么做了,但为了得到所有的头衔,它仍然不起作用:
f = open('output.xml','wb+')
f.write(r.content)
f.close()
tree = ""
with open('output.xml', 'rt') as f:
tree = ElementTree.parse(f)
print tree
root = tree.getroot()
for elem in tree.iter():
print elem.tag, elem.attrib
for atype in tree.findall('title'):
print atype.contents
或者找到标题和内容:
相关问题 更多 >
编程相关推荐