我执行这些行:蟒蛇feedparser不一致的项目
import feedparser
url = 'https://dl.dropboxusercontent.com/u/5724095/TutorialFeed/feed.xml'
feed = feedparser.parse(url)
items = feed['items']
print items[0]['links'][1]['href]
即采用这种feedparser module。这是有问题的RSS源的采样区块:
<item>
<title>More Android Annotations</title>
<link>http://youtu.be/77pPceVicNI</link>
<description><![CDATA[Walkthrough that goes a little bit more indepth to show you the things that <a href="http://androidannotations.org">AndroidAnnotations</a> can do for you as an application developer. <br /><a href="https://dl.dropboxusercontent.com/u/5724095/TutorialFeed/StackSitesAnnotations.mp4">Direct download link <i>(rightclick and choose save as)</i></a>]]></description>
<image>
<url>https://dl.dropboxusercontent.com/u/5724095/images/Githubpics/moreAnnotations.png</url>
<link>https://github.com/FoamyGuy/StackSites</link>
<title>More Android Annotations</title>
</image>
</item>
我试图获得该项目的https://github.com/FoamyGuy/StackSites
部分。在我的本地电脑上(win7 python 2.6),这个工作正常。但是当我在控制台上执行相同的代码时,我的github链接是pythonanywhere.com而不是我的github链接,我得到https://dl.dropboxusercontent.com/u/5724095/TutorialFeed/StackSitesAnnotations.mp4
这是在说明中CDATA结尾附近包含的mp4链接。
在两台机器上items[0]['links']
只包含2个元素(索引0和1),但索引1处的字符串的值在两台机器上不同。为什么feedparser会在一台机器上给我不同的值而不是另一台呢?
我已经在pythonanywhere上打印了整个items[0]
,并且我的github链接根本不包含在其中。是否有一些参数可以用来改变feed解析的方式,这样我就可以正确地获取github链接了吗?
是否有一些其他的feed解析模块对我更好,希望在机器上更一致?
它可能是某种地理位置的东西? PythonAnywhere服务器在美国,也许你住在某个地方,服务器根据IP返回不同的结果? – hwjp
我住在美国,(我认为pythonanywhere是基于英国的)。但无论哪种方式,它不应该是一个地理定位问题,因为有问题的XML是在我的控制之下,不应该根据地区而改变。 – FoamyGuy