开发者

lxml findall() problem

Just trying to make a simple program to get wikipedia's recentchanges and parse that XML file.

I stuck at the point where findall() not working. What I'm doing wrong?

import urllib2
from lxml import etree as ET

result = urllib2.urlopen('开发者_C百科http://en.wikipedia.org/w/api.php?action=query&format=xml&list=recentchanges&rcprop=title|ids|sizes|flags|user|timestamp').read()

xml=ET.fromstring (result)

print xml[0][0][0].attrib # that works!

print xml.findall ('api/query/recentchanges/rc') # that don't!


I suspect the root node is the topic node, so it's looking for a node named "api" inside of the root node. If so, both of the following will work:

query/recentchanges/rc

/api/query/recentchanges/rc
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜