日期:2014-05-20  浏览次数:20873 次

正则表达式匹配网页中的内容
如何匹配网页中的“药监局躲猫猫”,"孔融让梨我不让"?

<div class="content">
<h1 class="top10">实时热点排行榜<a onClick="javascript:clickmonkey.log('http://top.baidu.com/add.html?bid=top10&na=%25E5%25AE%259E%25E6%2597%25B6%25E7%2583%25AD%25E7%2582%25B9%25E6%258E%2592%25E8%25A1%258C%25E6%25A6%259C','');window.open('http://top.baidu.com/add.html?bid=top10&na=%25E5%25AE%259E%25E6%2597%25B6%25E7%2583%25AD%25E7%2582%25B9%25E6%258E%2592%25E8%25A1%258C%25E6%25A6%259C', 'newwindow', 'top=0,left=0,status=no,menubar=no,resizable=no,location=no,scrollbars=no,toolbar=no,directories=0,width=820,height=507');void(0);" class="add-list"><img src="img/add-list.gif" width="176" height="18" alt="将此榜单添加到我的网站" /></a></h1>
<div class="list">
<table cellspacing="0">
<tbody>


<tr class="th"><td>排名</td><td colspan="2">关键词</td><td>最近24小时搜索量</td><td>变化率</td><td>相关链接</td></tr>


<tr>
<th>1</th>
<td class="key"><a href="detail.php?b=1&w=%D2%A9%BC%E0%BE%D6%B6%E3%C3%A8%C3%A8" target="_blank">药监局躲猫猫</a></td>
<td><a href="http://www.baidu.com/baidu?cl=3&tn=baidutop10&fr=top1000&wd=%D2%A9%BC%E0%BE%D6%B6%E3%C3%A8%C3%A8" target="_blank" class="detail"></a></td>

<td>28620</td>
<td>1153720%</td>

<td><a href="http://news.baidu.com/ns?tn=news&from=news&cl=2&rn=20&ct=0&word=%D2%A9%BC%E0%BE%D6%B6%E3%C3%A8%C3%A8" target="_blank" class="line">新闻</a>
<a href="http://tieba.baidu.com/f?kw=%D2%A9%BC%E0%BE%D6%B6%E3%C3%A8%C3%A8" target="_blank" class="line">贴吧</a>
<a href="http://video.baidu.com/v?ct=301989888&rn=20&pn=0&db=0&s=0&word=%D2%A9%BC%E0%BE%D6%B6%E3%C3%A8%C3%A8" target="_blank" class=""><span class="link zoom"></span></a>
</td>
  </tr>

<tr>
<th>2</th>
<td class="key"><a href="detail.php?b=1&w=%BF%D7%C8%DA%C8%C3%C0%E6%CE%D2%B2%BB%C8%C3" target="_blank">孔融让梨我不让</a></td>
<td><a href="http://www.baidu.com/baidu?cl=3&tn=baidutop10&fr=top1000&wd=%BF%D7%C8%DA%C8%C3%C0%E6%CE%D2%B2%BB%C8%C3" target="_blank" class="detail"></a></td>

<td>10079</td>
<td>436087%</td>

<td><a href="http://news.baidu.com/ns?tn=news&from=news&cl=2&rn=20&ct=0&word=%BF%D7%C8%DA%C8%C3%C0%E6%CE%D2%B2%BB%C8%C3" target="_blank" class="line">新闻</a>
<a href="http://tieba.baidu.com/f?kw=%BF%D7%C8%DA%C8%C3%C0%E6%CE%D2%B2%BB%C8%C3" target="_blank" class="line">贴吧</a>
<a href="http://video.baidu.com/v?ct=301989888&rn=20&pn=0&db=0&s=0&word=%BF%D7%C8%DA%C8%C3%C0%E6%CE%D2%B2%BB%C8%C3" target="_blank" class=""><span class="link zoom"></span></a>
</td>
  </tr>

------解决方案--------------------
当然如果你的有标签嵌套的话,或者多个a标签,可能就不行咯。先把对应的标签找出来,然后再这样获取值