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
精彩评论