2012-05-21 4 views
0

J'ai une application moteur Google app et j'essaie d'utiliser feedparser pour accéder à un commentaire sur le flux. Je teste avec un flux d'exemple Google Bloggeraccéder aux commentaires en utilisant feedparser

<?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> 

Actuellement, mon code a

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

Je reçois le message d'erreur

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

Comment puis-je accéder aux commentaires et tout de ses attributs?

Merci

Répondre

1

Il ressemble à la notation de points à savoir child.thr_in-réponse-to.href ne fonctionne pas pour d'autres espaces de noms. Quand je l'ai changé à

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

cela a fonctionné.

Cependant, la notation des points fonctionne toujours pour l'espace de noms atome-à-dire d'accéder à l'identification d'une entrée, je suis encore capable de faire

child.id 
+0

C'est parce que 'thr_in-réponse-to' est pas valide Python identifiant. En effet, c'est l'expression 'thr_in - reply - to', et thr_in n'est pas un attribut de flux. –

Questions connexes