最近在項目中,我希望能通過grep實現從一個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/>優酷網</a> <a href="結果如下: 因為這種模式是貪婪匹配模式。我希望能用非貪婪模式,來進行匹配,方法是通過在*修飾副后面添加\?,修改如下: C:\tmp>grep -ior "href=.*\?\/>" a.txt 我期望的結果如下: 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="
結果如下:
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
不知道如何實現。如果您有解決方案,請多多指導。先謝了。
|----------------------------------------------------------------------------------------|
版權聲明 版權所有 @zhyiwww
引用請注明來源 http://www.aygfsteel.com/zhyiwww
|----------------------------------------------------------------------------------------|