免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2486 | 回复: 3
打印 上一主题 下一主题

请问如何用sed提取网页内容? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-06-08 22:48 |只看该作者 |倒序浏览
比如如下html代码,如何用sed提取<p class="content">和</p>标签之间的内容?  谢!



<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
.floatLeft{float: left;}
.image-left{float: left; vertical-align: text-top; padding-right:15px;}
.content{}
div.wrapContainer{width:99.5%; float:left; maring:0px;}
  body {margin: 0px;}
</style>
</head>
<body>
<table border=0 align="center" cellpadding="0" width="100%">
  <tr>
    <td align="center">
<div class="wrapContainer">
<p class="image-left"><img src="http://boulat.googlepages.com/cookie.png" alt="Linux Fortune Cookie" border="0"></p>
<p class="content">It's no wonder they call it WinNT; WNT = VMS++;

   -- Chris Abbey
%
Peace, Love and Compile the kernel...

   -- Justin L. Herreman
</p>
</div>
<br>
<div align="right"><a href="./cookie.php">next &raquo;</a></div>
</td>
</tr></table>
</body>
</html>

论坛徽章:
0
2 [报告]
发表于 2012-06-09 09:39 |只看该作者
本帖最后由 jiejie455 于 2012-06-09 09:41 编辑
  1. sed -nr '/<p class="content">/{:a N;/<\/p>/!ba;s/<p class="content">//;s/(.*)\n(.*)/\1/;p}' data
复制代码

论坛徽章:
0
3 [报告]
发表于 2012-06-09 13:40 |只看该作者
哇,好长啊,谢谢。:wink:

论坛徽章:
0
4 [报告]
发表于 2012-06-09 13:50 |只看该作者
能够简单解释一下是如何匹配的吗?)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP