怎么深度抓取网页

enasp 2009-03-31 10:33:17

http://www.tianya.cn/index.htm?vitem=http%3A%2F%2Fwww%2Etianya%2Ecn%2Fpublicforum%2Farticleslist%2F0%2Fworldlook%2Eshtml



怎么能把帖子的标题与正文一一抓下来保存?

以上如果只抓那页,那就只抓了标题,作者,日期,但抓到每个贴对应的具体内容
...全文
140 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
怪怪 2011-07-15
  • 打赏
  • 举报
回复
我也想抓取内容!
cyz9977 2009-03-31
  • 打赏
  • 举报
回复

<HTML>
<head>
<meta name="GENERATOR" content="Microsoft Visual Studio 6.0">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
<meta http-equiv="expires" content="0">
<meta name="keywords" content="天涯,天涯社区,博客,部落,相册,我的天涯,网藏,tianya,tianyaclub">
<meta name="description" content="天涯虚拟社区---海南天涯在线网络科技有限公司">
<title>
天涯社区--全球华人网上家园
</title>
<script language="JavaScript" src="http://static.tianya.cn/js/global/readCookieKeys.js" charset="gb2312">
</script>
<script language="JavaScript" src="http://static.tianya.cn/js/global/refleshCookie.js" charset="gb2312">
</script>
</head>

<script language="javascript" src="http://static.tianya.cn/js/global/leftlist_cache.js?v=20090326">
</script>
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.please connect with
WangJianke. </p>
</body>
</noframes>
</frameset>

</html>
enasp 2009-03-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wjhx 的回复:]
递归+正则表达式
[/Quote]

能不能给个例子,或代码?
wjhx 2009-03-31
  • 打赏
  • 举报
回复
递归+正则表达式
wuyq11 2009-03-31
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20090323/08/33208F23-A459-4D9F-A1A4-75D8A06E7B28.html
http://topic.csdn.net/u/20080104/17/6B14BA76-3948-46E2-9CE4-08F3C90AEAA8.html
enasp 2009-03-31
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 xiequan2 的回复:]
//取得输入的URL地址
PageUrl = UrlText.Text;
WebClient wc = new WebClient();
//把已登录的用户或正被模拟的用户的用户凭据赋给用于对向Internet资源的请求进行身份验证的网络凭据
wc.Credentials = CredentialCache.DefaultCredentials;

///方法一:
///从指定的URI下载数据
Byte[] pageData = wc.DownloadData(PageUrl);
//把下载到的字符型数组数据转换成字符串类型
ContentHtml.Text = Encoding.Defa…
[/Quote]

这只能取到当面页面的标题,不能取到正文吧(href=“”的内容没法取出来)
xiequan2 2009-03-31
  • 打赏
  • 举报
回复
//取得输入的URL地址
PageUrl = UrlText.Text;
WebClient wc = new WebClient();
//把已登录的用户或正被模拟的用户的用户凭据赋给用于对向Internet资源的请求进行身份验证的网络凭据
wc.Credentials = CredentialCache.DefaultCredentials;

///方法一:
///从指定的URI下载数据
Byte[] pageData = wc.DownloadData(PageUrl);
//把下载到的字符型数组数据转换成字符串类型
ContentHtml.Text = Encoding.Default.GetString(pageData);

/// 方法二
//为指定的URI打开一个可读的数据流,并定义一个该流的引用
/// Stream resStream = wc.OpenRead(PageUrl);
/// 根据上面定义的数据流,以默认编码的方式定义一个读数据流
/// StreamReader sr = new StreamReader(resStream,System.Text.Encoding.Default);
/// 读取数据流中的内容
/// ContentHtml.Text = sr.ReadToEnd();
/// //关闭数据流
/// resStream.Close();
///
//释放资源
wc.Dispose();
enasp 2009-03-31
  • 打赏
  • 举报
回复
同时抓到这个链接的内容

<a href='http://www.tianya.cn/publicforum/content/worldlook/1/208071.shtml' target='_blank'>
enasp 2009-03-31
  • 打赏
  • 举报
回复

<table width=640 border=0 cellspacing=0>
<tr><td width=20><font face=wingdings color=blue>K</font> </td><td width=370><a href='http://www.tianya.cn/publicforum/content/worldlook/1/213494.shtml' target='_blank'><font color=red>[任前公示]关于拟恢复 尼丹小 为[国际观察]版主的任前公示</a></td>
<td width=90><a href='/browse/Listwriter.asp?vwriter=天涯社会社区' target=_blank onmouseover="if(im_popMenu) im_popMenu(this,'天涯社会社区','天涯社会社区')" onmouseout="if(im_beginCloseMenu) im_beginCloseMenu(this);">天涯社会社区</a></td>
<td width=35 align=center class=tdfont>18513</td>
<td width=35 align=center class=tdfont>724</td>
<td width=90 align=center class=tdfont>3-31 14:16</td>
</table>
<table width=640 border=0 cellspacing=0 bgcolor='#eeefff'>
<tr><td width=20><font face=wingdings color=blue>K</font> </td><td width=370><a href='http://www.tianya.cn/publicforum/content/worldlook/1/213598.shtml' target='_blank'>萨科齐称建议若遭否决将抵制G20峰会(转载)</a></td>
<td width=90><a href='/browse/Listwriter.asp?vwriter=爱走刀口的鱼' target=_blank onmouseover="if(im_popMenu) im_popMenu(this,'爱走刀口的鱼','爱走刀口的鱼')" onmouseout="if(im_beginCloseMenu) im_beginCloseMenu(this);">爱走刀口的鱼</a></td>
<td width=35 align=center class=tdfont>995</td>
<td width=35 align=center class=tdfont>6</td>
<td width=90 align=center class=tdfont>3-31 14:15</td>
</table>
<table width=640 border=0 cellspacing=0>
<tr><td width=20><font face=wingdings color=blue>K</font> </td><td width=370><a href='http://www.tianya.cn/publicforum/content/worldlook/1/208071.shtml' target='_blank'>钓鱼岛,我们不能再沉默!</a></td>
<td width=90><a href='/browse/Listwriter.asp?vwriter=neil_wang_yeah' target=_blank onmouseover="if(im_popMenu) im_popMenu(this,'neil_wang_yeah','neil_wang_yeah')" onmouseout="if(im_beginCloseMenu) im_beginCloseMenu(this);">neil_wang_yeah</a></td>
<td width=35 align=center class=tdfont>20949</td>
<td width=35 align=center class=tdfont>525</td>
<td width=90 align=center class=tdfont>3-31 14:15</td>
</table>

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧