【问题标题】:python rss feedparser can't parse description correctlypython rss feedparser 无法正确解析描述
【发布时间】:2015-05-20 15:03:37
【问题描述】:

我的 Python 代码无法解析来自 RSS 提要的“描述”,当我运行以下脚本时,它显示多行空白,我该如何正确解析它?

import feedparser
import unidecode
rss_url = "http://my.blogspot.com/feeds/posts/default?alt=rss"
feed = feedparser.parse( rss_url )
for key in feed["entries"]:
    print unidecode.unidecode(key["description"])

RSS 描述部分:

<description>&lt;iframe src=&quot;https://domain.com/embed/NTXFZhHw/01-10-1080p.mp4&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; width=&quot;700&quot; height=&quot;430&quot; allowfullscreen=&quot;true&quot; webkitallowfullscreen=&quot;true&quot; mozallowfullscreen=&quot;true&quot;&gt;&lt;/iframe&gt;  </description>

【问题讨论】:

  • 每个提要都会出现这种情况,还是只是一个特定的提要?如果只有一个提要,则其中一个描述字段中可能存在有问题的字符。
  • 只有我的提要,因为我的提要有很多奇怪的字符。我该如何解决?

标签: python python-2.7 rss feedparser blogspot


【解决方案1】:

请替换:

import feedparser

与:

import feedparser
feedparser._HTMLSanitizer.acceptable_elements.update(['iframe'])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 2013-11-03
    相关资源
    最近更新 更多