python rss feedparser无法正确解析描述

时间:2015-05-20 15:03:37

标签: python python-2.7 rss feedparser blogspot

我的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>

1 个答案:

答案 0 :(得分:3)

请替换:

import feedparser

使用:

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