使用feedparser访问评论

时间:2012-05-21 03:56:08

标签: google-app-engine feedparser

我有一个Google应用引擎应用,我正在尝试使用feedparser访问Feed上的评论。我正在使用Google博客示例

中的Feed进行测试
<?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?>
<feed xmlns='http://www.w3.org/2005/Atom'
   xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/'
   xmlns:gd='http://schemas.google.com/g/2005'
   gd:etag='W/"CUYMQ348fyp7ImA9WB9UFkU."'>
  <id>tag:blogger.com,1999:blog-blogID.postpostID..comments</id>
  <updated>2007-12-14T17:46:22.077-08:00</updated>
  <title>Comments on Lizzy's Diary: Quite disagreeable</title>
  <entry gd:etag='W/"CUYCQX47eSp7ImA9WB9UFkU."'>
     <id>tag:blogger.com,1999:blog-blogID.post-commentID</id>
     <published>2007-12-14T17:46:00.001-08:00</published>
     <thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' 
        href='http://blogName.blogspot.com/2007/12/quite-disagreeable_5283.html'
        ref='tag:blogger.com,1999:blog-blogID.post-postID'
        source='http://www.blogger.com/feeds/blogID/posts/default/postID'
        type='text/html' />
  </entry>

目前,我的代码已

d= feedparser.parse(feedurl)
for child in d.entries:
   _url = child.thr_in-reply-to.href

我收到错误消息

raise AttributeError, &quot;object has no attribute '%s'&quot; % key
AttributeError: object has no attribute 'thr_in'

如何访问评论及其任何属性?

由于

1 个答案:

答案 0 :(得分:1)

看起来像点符号,即 child.thr_in-reply-to.href 不适用于其他名称空间。当我把它改成

child['thr_in-reply-to']['href']

它有效。

然而,点符号仍然适用于atom命名空间,即访问条目的id,我仍然可以

child.id