【问题标题】:how to parse html text file in terminal?如何在终端中解析 html 文本文件?
【发布时间】:2017-12-02 21:05:45
【问题描述】:

我有一个文本文件,即使在删除所有 html 标记后仍然包含一些 html 代码的撇号和其他标点符号示例:

  It's  // It's 

我的问题是如何全部更改?

我在linux下使用bash脚本来获取html文件

【问题讨论】:

    标签: html linux bash gnome-terminal


    【解决方案1】:

    或者,如果您有 lynx,请将其用作:

    lynx -stdin -dump < file.html
    

    上面也将删除 HTML 标记,例如来自 file.html

    <i>It&#039;s</i>
    &lt;<b>&amp;</b>&#62;
    

    打印

       It's <&>
    

    【讨论】:

      【解决方案2】:

      使用 Python:

      $ echo 'It&#039;s' | python -c 'import xmllib,sys; print(xmllib.XMLParser().translate_references(sys.stdin.read()))'
      It's
      

      使用 Perl:

      $ echo 'It&#039;s' | perl -MHTML::Entities -pe 'decode_entities($_);'
      It's
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多