Chinaunix
标题:
刚学Linux,问个正则问题
[打印本页]
作者:
LIUXURONG
时间:
2008-08-29 19:05
标题:
刚学Linux,问个正则问题
:( 想了很久也没想出~~怎么抓一个网页的所有 URL ?
偶是这么想的,先用w3m取出网页代码, 然后用Sed 工具对吗?那正则要怎么写呢?
作者:
jactive
时间:
2008-08-29 19:34
sed -n -e :a -e 's/.*href=\"\([^"]\+\)\"/\1\n/gp' htm | sed -n -e '1~2p'
使用这个网页测试过了,不过要求 href="..." 而不能是 href='....'
顺便作个广告:))) 帮忙看看这个哈:
http://bbs.chinaunix.net/thread-1255760-1-1.html
[
本帖最后由 jactive 于 2008-8-29 19:36 编辑
]
作者:
LIUXURONG
时间:
2008-08-29 21:47
哇.谢谢了.我现在试试
作者:
LIUXURONG
时间:
2008-08-29 21:56
用不了。。
看了半天没看明白
作者:
jactive
时间:
2008-08-29 22:17
标题:
回复 #4 LIUXURONG 的帖子
有什么提示? htm 是一个 html文件
顺便作个广告:))) 帮忙解决一下这个问题:
http://bbs.chinaunix.net/thread-1255760-1-1.html
帮顶也很感谢
作者:
LIUXURONG
时间:
2008-08-30 01:43
抓不完整。。这是百度首页的代码 ^_^ 您试一下。
<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>新 闻</a><b>网 页</b><a onclick=s(this) href=http://tieba.baidu.com>贴 吧</a><a onclick=s(this) href=http://zhidao.baidu.com>知 道</a><a onclick=s(this) href=http://mp3.baidu.com>MP3</a><a onclick=s(this) href=http://image.baidu.com>图 片</a><a onclick=s(this) href=http://video.baidu.com>视 频</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> <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> <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> | <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>©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-->
作者:
寂寞烈火
时间:
2008-08-30 09:38
grep -o -E 'http://.*.(com|net|org|cn)'
作者:
jactive
时间:
2008-08-30 14:11
baidu我没试过,我只在这个网页的代码上试了,你自己在改改吧
作者:
springwind426
时间:
2008-08-30 21:16
wget -q -O- URL 2>/dev/null | grep -o '<a [^>]*>' | sed "s/.*href=[\"']\?\([^> '\"]*\)[> '\"].*/\1/"
复制代码
作者:
无声无息
时间:
2008-08-31 00:34
标题:
回复 #9 springwind426 的帖子
考虑的真是周到
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2