错误记录:贴吧爬取

1:为什么匹配不出url链接:找到原因了,不是正则表达式的问题原来从浏览器里贴出了的源代码和调用java包返回的源代码不同(原因不明)如下

浏览器:

<tbody id="normalthread_14777">
<tr>
<td class="icn">
<a href="thread-14777-1-1.html" title="新窗口打开" target="_blank">
<img src="static/image/common/folder_common.gif" />
</a>
</td>
<th class="common">
 <a href="thread-14777-1-1.html" style="font-weight: bold;color: #2B65B7" οnclick="atarget(this)" class="xst" >青岛5所高中要搬迁,19中搬迁鳌山卫,配套山大青岛校区</a>
</th>
<td class="by">
<cite>
<a href="home.php?mod=space&amp;uid=3324" c="1">number11</a></cite>
<em><span>2012-2-29</span></em>
</td>
<td class="num"><a href="thread-14777-1-1.html" class="xi2">6</a><em>657</em></td>
<td class="by">
<cite><a href="home.php?mod=space&username=%E5%8D%81%E5%85%AD%E7%9A%84%E6%9C%88%E4%BA%AE" c="1">十六的月亮</a></cite>
<em><a href="forum.php?mod=redirect&tid=14777&goto=lastpost#lastpost">2012-3-6 20:46:40</a></em>
</td>
</tr>
</tbody>

java包返回的:

<tbody id="normalthread_14777">

<tr>
<td class="icn">
<a href="thread-15648-1-1.html" title="有新回复 - 新窗口打开" target="_blank">
<img src="static/image/common/folder_new.gif" />
</a>
</td>
<th class="new">
 <a href="thread-15648-1-1.html" οnclick="atarget(this)" class="xst" >山东大学校董会名誉主席梁振英当选香港第四任特首</a>
<a href="forum.php?mod=redirect&amp;tid=15648&amp;goto=lastpost#lastpost" class="xi1">New</a>
</th>
<td class="by">
<cite>
<a href="home.php?mod=space&amp;uid=2109" c="1">liuzhiwu</a></cite>
<em><span class="xi1">2012-3-26</span></em>
</td>
<td class="num"><a href="thread-15648-1-1.html" class="xi2">0</a><em>1</em></td>
<td class="by">
<cite><a href="home.php?mod=space&username=liuzhiwu" c="1">liuzhiwu</a></cite>
<em><a href="forum.php?mod=redirect&tid=15648&goto=lastpost#lastpost"><span title="2012-3-26 10:28:41">4&nbsp;分钟前</span></a></em>
</td>
</tr>

</tbody>

其中链接前的class标签不同,浏览器重的是common而java返回的是new。

所以使正则表达式不能正确的匹配出链接来

 

 

2错误2:解析得到了url链接,却无法解析得到帖子内容(http://bbs.sdu.edu.cn/forum-242-2.html

解析得到的url为:http://bbs.sdu.edu.cn/forum.php?mod=viewthread&amp;tid=15626&amp;extra=page%3D1%26filter%3Dsortid%26sortid%3D4%26sortid%3D4

用正则表达式解析式将&自动转译成&amp;使得不能正常返回网页内容。

用java中的字符串处理将&amp;在转译成&就会得到如下正确地址:

http://bbs.sdu.edu.cn/forum.php?mod=viewthread&tid=15626&extra=page%3D1%26filter%3Dsortid%26sortid%3D4%26sortid%3D4


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WitsMakeMen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值