【问题标题】:FeedparserDict object doesn't have 'content' attributeFeedparserDict 对象没有“内容”属性
【发布时间】:2014-06-13 05:34:55
【问题描述】:

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

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'

【问题讨论】:

    标签: feedparser


    【解决方案1】:

    只要做一个 print(post),你可能会发现它没有 content 属性。 RSS 提要并不能保证一定会有。

    【讨论】:

      猜你喜欢
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 2021-08-03
      • 2017-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多