bash:在一对HTML标签之间获取内容 [英] bash: get content between a pair of HTML tags

查看:124
本文介绍了bash:在一对HTML标签之间获取内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用bash脚本获取一对给定标签之间的HTML内容。
以下面的HTML代码为例:

I need to get the HTML contents between a pair of given tags using a bash script. As an example, having the HTML code below:

<html>
<head>
</head>
<body>
 text
  <div>
  text2
    <div>
        text3
    </div>
  </div>
</body>
</html>

使用bash命令/脚本,给定 body 标记,我们会得到:

Using the bash command/script, given the body tag, we would get:

 text
  <div>
  text2
    <div>
    text3
    </div>
  </div>

预先致谢。

Thanks in advance.

推荐答案

纯文本处理不利于html / xml解析。我希望这可以给你一些想法:

plain text processing is not good for html/xml parsing. I hope this could give you some idea:

kent$  xmllint --xpath "//body" f.html 
<body>
 text
  <div>
  text2
    <div>
        text3
    </div>
  </div>
</body>

这篇关于bash:在一对HTML标签之间获取内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆