正在解析 iPhone App Store RSS XML

parsing iPhone App Store RSS XML

我很难解析 App Store xml 以提取 appID 的评级。(appID 是 298307011)

XML: https://itunes.apple.com/us/rss/customerreviews/id=298307011/xml

我试图为每个应用评论条目提取的评级是 。树形结构为root > entry -> im:rating

我的代码没有获取评分文本。

import urllib2
import xml.etree.ElementTree as ET
url = 'https://itunes.apple.com/us/rss/customerreviews/id=298307011/xml'

xml_string = urllib2.urlopen(url).read()
root = ET.fromstring(xml_string)


for rating in root.iter('im:rating'):
    print rating.text

看来您需要添加命名空间并使用 iter

以外的东西

使用 lmxl 和 xpath:

import urllib2
import lxml.etree as etree
url = 'https://itunes.apple.com/us/rss/customerreviews/id=298307011/xml'

xml_string = urllib2.urlopen(url).read()
root = etree.fromstring(xml_string)


for rating in root.xpath('//im:rating', namespaces={'im':'http://itunes.apple.com/rss'}):
    print rating.text