最近在項(xiàng)目中,我希望能通過grep實(shí)現(xiàn)從一個(gè)html頁面中檢索出所有的超鏈接,
比如下面的一段代碼
<tr class=rb><td class=pl><a href=mail.htm>郵 箱</a></td><td><a href=http://mail.163.com/>163郵箱</a>
<a href="? <a href=http://mail.sina.com.cn/>新浪郵箱</a> <a href=http://mail.qq.com/>QQ郵箱</a> <a href=http://www.hotmail.com/>Hotmail</a></td><td><a href=mail.htm>更多 »</a></td></tr>
<tr class=ry><td class=pl><a href=wangmei.htm>視 頻</a></td><td><a href=http://www.youku.com/>優(yōu)酷網(wǎng)</a> <a href="結(jié)果如下: 因?yàn)檫@種模式是貪婪匹配模式。我希望能用非貪婪模式,來進(jìn)行匹配,方法是通過在*修飾副后面添加\?,修改如下: C:\tmp>grep -ior "href=.*\?\/>" a.txt 我期望的結(jié)果如下: href=mail.htm
<tr class=rb><td class=pl><a href=mail.htm>郵 箱</a></td><td><a href=http://mail.163.com/>163郵箱</a> <a href="
結(jié)果如下:
href=mail.htm>郵 箱</a></td><td><a href=http://mail.163.com/>163郵箱</a> <a href="http://cn.mail.yahoo.com/?id=40014
" class="greenfont">雅虎郵箱</a> <a href=http://www.126.com/>126郵箱</a> <a href=http://mail.sina.com.cn/>新浪郵
箱</a> <a href=http://mail.qq.com/>QQ郵箱</a> <a href=http://www.hotmail.com/>
href=http://mail.163.com/
href=
href=http://www.126.com/
href=http://mail.sina.com.cn/
href=http://mail.qq.com/
href=http://www.hotmail.com/
href=mail.htm
不知道如何實(shí)現(xiàn)。如果您有解決方案,請多多指導(dǎo)。先謝了。
|----------------------------------------------------------------------------------------|
版權(quán)聲明 版權(quán)所有 @zhyiwww
引用請注明來源 http://www.aygfsteel.com/zhyiwww
|----------------------------------------------------------------------------------------|