gpt4 book ai didi

python - feedparser 无法获取 youtube 播放器

转载 作者:太空宇宙 更新时间:2023-11-04 09:12:48 24 4
gpt4 key购买 nike

我正在测试 feedparser 在我的 rss 提要上。它就像一个魅力,我得到了所有条目。

一些新闻有一个嵌入的 youtube 播放器,但这并没有出现在 feedparser 的返回值中。

我的代码很简单:

d = feedparser.parse('http://feeds.feedburner.com/NotciasPs3evita-Mypst')

返回(摘录):

 guidislink': False,
'id': u'http://mypst.com.br/forum/index.php?/topic/17336-gamegen-call-of-duty-black-ops-2-ganha-trailer-com-acao-real-e-muitas-surpresas/',
'link': u'http://mypst.com.br/forum/index.php?/topic/17336-gamegen-call-of-duty-black-ops-2-ganha-trailer-com-acao-real-e-muitas-surpresas/',
'links': [{'href': u'http://mypst.com.br/forum/index.php?/topic/17336-gamegen-call-of-duty-black-ops-2-ganha-trailer-com-acao-real-e-muitas-surpresas/',
'rel': u'alternate',
'type': u'text/html'}],
'published': u'Mon, 29 Oct 2012 14:53:58 +0000',
'published_parsed': time.struct_time(tm_year=2012, tm_mon=10, tm_mday=29, tm_hour=14, tm_min=53, tm_sec=58, tm_wday=0, tm_yday=303, tm_isdst=0),
'summary': u'A Activision revelou hoje um novo trailer de Call of Duty: Black Ops 2, substituindo as cenas de a\xe7\xe3o do jogo por cenas de a\xe7\xe3o na vida real. O trailer traz diversas \u201csurpresas\u201d e alguns zumbis.<br />\n<br />\n<br />\n<br />\nCall of Duty: Black Ops 2 chegar\xe1 no dia 13 de novembro nos Estados Unidos.<br />\n<br />\n<br />\n<em class="bbc"><strong class="bbc">Fonte: <a class="bbc_url" href="http://www.gamegen.com.br/playstation3/call-of-duty-black-ops-2-ganha-trailer-com-acao-real-e-muitas-surpresas/" rel="nofollow external" title="Link externo">GameGeneration</a></strong></em>',
'summary_detail': {'base': u'http://feeds.feedburner.com/NotciasPs3evita-Mypst',
'language': None,
'type': u'text/html',
'value': u'A Activision revelou hoje um novo trailer de Call of Duty: Black Ops 2, substituindo as cenas de a\xe7\xe3o do jogo por cenas de a\xe7\xe3o na vida real. O trailer traz diversas \u201csurpresas\u201d e alguns zumbis.<br />\n<br />\n<br />\n<br />\nCall of Duty: Black Ops 2 chegar\xe1 no dia 13 de novembro nos Estados Unidos.<br />\n<br />\n<br />\n<em class="bbc"><strong class="bbc">Fonte: <a class="bbc_url" href="http://www.gamegen.com.br/playstation3/call-of-duty-black-ops-2-ganha-trailer-com-acao-real-e-muitas-surpresas/" rel="nofollow external" title="Link externo">GameGeneration</a></strong></em>'},
'title': u'[GameGen] Call of Duty: Black Ops 2 ganha trailer com a\xe7\xe3o real e muitas surpresas',
'title_detail': {'base': u'http://feeds.feedburner.com/NotciasPs3evita-Mypst',
'language': None,
'type': u'text/plain',
'value': u'[GameGen] Call of Duty: Black Ops 2 ganha trailer com a\xe7\xe3o real e muitas surpresas'}},

除了 youtube 播放器外,一切都已就绪 <object>标签。这是 feedparser 错误还是我的 rss 有问题? python 上是否有其他库可以执行此操作?

最佳答案

提要解析器 sanitizes HTML input<object> , <param><embed>标签默认被剥离。

您需要禁用清理(仅当您真正信任来源时),或将 YouTube 标签列入白名单。

要禁用清理,请设置 SANITIZE_HTML错误:

feedparser.SANITIZE_HTML = False

要添加到白名单,将元素添加到_HTMLSanitizer.acceptable_elements设置:

_HTMLSanitizer.acceptable_elements.update(['object', 'param', 'embed'])

这两种方法都有固有的风险,您会以这种方式让自己受到攻击。我使用的方法是完全切换 sanitizer ,然后使用 some other method清理 HTML,可能使用 lxml.html.clean使用白名单并在 host_whitelist 中列出 YouTube .

关于python - feedparser 无法获取 youtube 播放器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13125833/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com