FeedparserDict对象没有'content'属性

时间:2014-06-13 05:34:56

标签: feedparser

我正在尝试熟悉feedparser库,但我似乎无法访问feedparser对象中条目的content属性:

d = feedparser.parse('http://www.reddit.com/r/python/.rss')
post = d.entries[2]
post.content

上面的代码块给了我这个错误:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\feedparser.py", line 414, in __getattr__
    return self.__getitem__(key)
  File "C:\Python34\lib\site-packages\feedparser.py", line 375, in __getitem__
    return dict.__getitem__(self, key)
KeyError: 'content'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#87>", line 1, in <module>
    content = post.content[0].value
  File "C:\Python34\lib\site-packages\feedparser.py", line 416, in __getattr__
    raise AttributeError("object has no attribute '%s'" % key)
AttributeError: object has no attribute 'content'

1 个答案:

答案 0 :(得分:0)

只需打印(发布),您可能会发现它没有内容属性。 RSS提要不保证它会有一个。