我正在尝试解析这个 xml (http://www.reddit.com/r/videos/top/.rss) 并且在这样做时遇到了麻烦。我正在尝试将 youtube 链接保存在每个项目中,但由于“频道”子节点而遇到麻烦。我如何达到这个级别,然后我可以遍历这些项目?
#reddit parse
reddit_file = urllib2.urlopen('http://www.reddit.com/r/videos/top/.rss')
#convert to string:
reddit_data = reddit_file.read()
#close file because we dont need it anymore:
reddit_file.close()
#entire feed
reddit_root = etree.fromstring(reddit_data)
channel = reddit_root.findall('{http://purl.org/dc/elements/1.1/}channel')
print channel
reddit_feed=[]
for entry in channel:
#get description, url, and thumbnail
desc = #not sure how to get this
reddit_feed.append([desc])