【问题标题】:python feedparser - removing <script> tag and everything inside from feed after readingpython feedparser - 阅读后从提要中删除 <script> 标记和所有内容
【发布时间】:2015-01-16 16:16:27
【问题描述】:

我正在使用 feedparser 读取提要,提要中的某些内容包含类似

&lt;p&gt; some word &lt;/p&gt;

&lt;script&gt;
    (function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,"script","//www.google-analytics.com/analytics.js","ga");

      ga("create", "UA-wewewefwef-13", "www.wewefwef.com");
      ga("require", "displayfeatures");
      ga("set", "anonymizeip", true);
      ga("send", "pageview");
&lt;/script&gt;

它正在删除&amp;lt;script&amp;gt; 中的所有内容,只读取&amp;lt;p&amp;gt;。为什么?我究竟做错了什么?

好的,我发现in the docs feedparser 会自动清理脚本标签。但是如果我知道来源并且我想要那些脚本标签怎么办?我该如何解决这个问题?

【问题讨论】:

    标签: python django feedparser


    【解决方案1】:

    好的,我明白了:

    feedparser.SANITIZE_HTML = 0
    

    还有中提琴!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 2018-09-04
      • 2011-06-05
      • 2015-07-29
      • 2020-03-03
      • 2022-12-05
      相关资源
      最近更新 更多