使用Bash在一对HTML标签之间获取内容 [英] Get content between a pair of HTML tags using Bash

查看:156
本文介绍了使用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>

谢谢.

推荐答案

纯文本处理不适用于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天全站免登陆