免费注册 查看新帖 |

Chinaunix

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

刚学Linux,问个正则问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-29 19:19 |只看该作者 |倒序浏览
:( 想了很久也没想出~~怎么抓一个网页的所有 URL ?

偶是这么想的,先用w3m取出网页代码, 然后用Sed 工具对吗?那正则要怎么写呢?

论坛徽章:
0
2 [报告]
发表于 2008-08-29 19:28 |只看该作者
如果不是要研究正则,考虑使用wget吧。

论坛徽章:
0
3 [报告]
发表于 2008-08-29 21:46 |只看该作者

回复 #2 零二年的夏天 的帖子



偶说要取URL...

论坛徽章:
1
寅虎
日期:2015-01-23 02:35:47
4 [报告]
发表于 2008-08-29 22:16 |只看该作者
拿一段代码上来

论坛徽章:
0
5 [报告]
发表于 2008-08-30 01:26 |只看该作者
原帖由 cuci 于 2008-8-29 22:16 发表
拿一段代码上来


w3m -dump_source www.baidu.com | sed ...............

之后的正则不会写了~

论坛徽章:
1
寅虎
日期:2015-01-23 02:35:47
6 [报告]
发表于 2008-08-30 06:39 |只看该作者
我要代码,不是你的命令,我的机器没装w3m

论坛徽章:
0
7 [报告]
发表于 2008-08-30 07:06 |只看该作者
原帖由 LIUXURONG 于 2008-8-30 01:26 发表


w3m -dump_source www.baidu.com | sed ...............

之后的正则不会写了~

你也应该多 man 一下 w3m,看看 -dump_source 是干什么的再使用,我也是发这个贴子前刚看的,发现你用的不对
另外你应该先看一下 HTTP 协议标准,看 URL 是以什么形式存在的,即使你用对了也未必获得的到 URL

论坛徽章:
0
8 [报告]
发表于 2008-08-30 20:46 |只看该作者
原帖由 cuci 于 2008-8-30 06:39 发表
我要代码,不是你的命令,我的机器没装w3m



您是要百度首页的代码吗? 用sed 把 http://.......... 的URL取出来。。

不知道用sed对吗


<html><head><meta http-equiv=Content-Type content="text/html;charset=gb2312"><title>百度一下,你就知道      </title><style>body{margin:4px 0}p{margin:0;padding:0}img{border:0}td,p,#u{font-size:12px}#b,#u,#l td,a{font-family:arial}#kw{font:16px Verdana;height:1.78em;padding-top:2px}#b{height:30px;padding-top:4px}#b,#b a{color:#77c}#u{padding-right:10px;line-height:19px;text-align:right;margin:0 0 3px !important;margin:0 0 10px}#sb{height:2em;width:5.6em}#km{height:50px}#l{margin:0 0 5px 15px}#l td{padding-left:107px}p,table{width:650px;border:0}#l td,#sb,#km{font-size:14px}#l a,#l b{margin-right:1.14em}a{color:#00c}a:active{color:#f60}#hp{position:absolute;margin-left:6px}#lg{margin:-26px 0 -44px}#lk{width:auto;line-height:18px;vertical-align:top}</style></head>
<body><div id=u></div><center><img src=http://www.baidu.com/img/baidu_logo.gif width=270 height=129 usemap="#mp" id=lg><br><br><br><br><table cellpadding=0 cellspacing=0 id=l><tr><td><div id=m><a onclick=s(this) href=http://news.baidu.com>新&nbsp;闻</a><b>网&nbsp;页</b><a onclick=s(this) href=http://tieba.baidu.com>贴&nbsp;吧</a><a onclick=s(this) href=http://zhidao.baidu.com>知&nbsp;道</a><a onclick=s(this) href=http://mp3.baidu.com>MP3</a><a onclick=s(this) href=http://image.baidu.com>图&nbsp;片</a><a onclick=s(this) href=http://video.baidu.com>视&nbsp;频</a></div></td></tr></table>
<table cellpadding=0 cellspacing=0 style="margin-left:15px"><tr valign=top><td style="height:62px;padding-left:92px" nowrap><form name=f action=/s><input type=text name=wd id=kw size=42 maxlength=100><script>var w=document.f.wd;w.focus();document.getElementById("u").innerHTML='<a href="http://passport.baidu.com/?login&tpl=mn&u='+escape(location.href)+'">登录</a>';function s(o){if(w.value.length>0){var h=o.href;var q=encodeURIComponent(w.value);if(h.indexOf("q=")!=-1){o.href=h.replace(new RegExp("q=[^&$]*"),"q="+q)}else{o.href+="?q="+q}}};(function(){if(new RegExp("q=([^&]+)").test(location.search)){w.value=decodeURIComponent(RegExp.$1)}})()</script> <input type=submit value=百度一下 id=sb>&nbsp;<span id=hp><a href=/search/jiqiao.html>帮助</a><br><a href=/gaoji/advanced.html>高级</a></span></form></td></tr></table>
<p id=km><a href=http://hi.baidu.com>空间</a>&nbsp;&nbsp;<a href="http://www.hao123.com" onmousedown="(new Image()).src='http://s.baidu.com/w.gif?fm=index&title=hao123&t='+(new Date().getTime())">hao123</a>&nbsp;|&nbsp;<a href=/more/ style="font-family:宋体">更多>></a></p>
<p style=height:60px><table cellpadding=0 cellspacing=0 id=lk><tr><td></td></tr></table></p>
<p style=height:30px><a onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.baidu.com')" href=http://utility.baidu.com/traf/click.php?id=215&url=http://www.baidu.com>把百度设为首页</a></p><p style=height:14px><a href=http://jingjia.baidu.com>企业推广</a> | <a href=http://top.baidu.com>搜索风云榜</a> | <a href=/home.html>关于百度</a> | <a href=http://ir.baidu.com>About Baidu</a></p><p id=b>&copy;2008 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://www.miibeian.gov.cn target=_blank>京ICP证030173号</a> <img src=http://gimg.baidu.com/img/gs.gif></p><map name=mp><area shape=rect coords="43,22,227,91" href=http://hi.baidu.com/baidu/ target=_blank title="点此进入 百度空间"></map></center></body></html><!--e9619a3977e1e797-->

论坛徽章:
0
9 [报告]
发表于 2008-08-30 20:48 |只看该作者
原帖由 platinum 于 2008-8-30 07:06 发表

你也应该多 man 一下 w3m,看看 -dump_source 是干什么的再使用,我也是发这个贴子前刚看的,发现你用的不对
另外你应该先看一下 HTTP 协议标准,看 URL 是以什么形式存在的,即使你用对了也未必获得的到 URL


-dump_source
              dump page source into stdout

虽然偶英文不好。。
应该是把源码取出吧??
URL还有什么形式。。你看上一楼。就是文本形式。。

论坛徽章:
0
10 [报告]
发表于 2008-08-30 23:29 |只看该作者
沉了。。自己顶下。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP