首页
最近更新
热门教程
ASP.NET
开发语言
开发环境
AJax教程
控件开发
统计报表
数据库
Web服务
安装部署
HTML教程
Javascript
XML教程
Community Server
NHibernate
书籍推荐
常用工具
实用代码
教程全文搜索
首页
>>
admin的知识库
>>
.NET2.0抓取网页全部链接
添加人:
admin
添加时间:2007-08-11 阅读次数:1413
收藏此教程
效果图
后台代码:
1
using
System;
2
using
System.Data;
3
using
System.Configuration;
4
using
System.Web;
5
using
System.Web.Security;
6
using
System.Web.UI;
7
using
System.Web.UI.WebControls;
8
using
System.Web.UI.WebControls.WebParts;
9
using
System.Web.UI.HtmlControls;
10
using
System.Text.RegularExpressions;
11
using
System.Net;
12
using
System.IO;
13
using
System.Collections;
14
public
partial
class
_Default : System.Web.UI.Page
15
{
16
protected
void
Page_Load(
object
sender, EventArgs e)
17
{
18
if
(
!
IsPostBack)
19
{
20
21
}
22
23
}
24
25
protected
void
Button1_Click(
object
sender, EventArgs e)
26
{
27
TextBox2.Text
=
""
;
28
string
web_url
=
this
.TextBox1.Text;
29
string
all_code
=
""
;
30
HttpWebRequest all_codeRequest
=
(HttpWebRequest)WebRequest.Create(web_url);
31
WebResponse all_codeResponse
=
all_codeRequest.GetResponse();
32
StreamReader the_Reader
=
new
StreamReader(all_codeResponse.GetResponseStream());
33
all_code
=
the_Reader.ReadToEnd();
34
the_Reader.Close();
35
ArrayList my_list
=
new
ArrayList();
36
string
p
=
@"
http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?
"
;
37
Regex re
=
new
Regex(p, RegexOptions.IgnoreCase);
38
MatchCollection mc
=
re.Matches(all_code);
39
for
(
int
i
=
0
; i
<=
mc.Count
-
1
; i
++
)
40
{
41
bool
_foo
=
false
;
42
string
name
=
mc[i].ToString();
43
foreach
(
string
list
in
my_list)
44
{
45
if
(name
==
list)
46
{
47
_foo
=
true
;
48
break
;
49
}
50
}
//
过滤
51
if
(
!
_foo)
52
{
53
TextBox2.Text
+=
name
+
"
"
;
54
}
55
}
56
}
57
}
58
前台
1
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
_Default
"
%>
2
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
3
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
4
<
head
runat
="server"
>
5
<
title
>
抓取网页所有链接
</
title
>
6
7
</
head
>
8
<
body
>
9
<
form
id
="form1"
runat
="server"
>
10
<
div
>
11
<
asp:TextBox
ID
="TextBox1"
runat
="server"
Width
="481px"
></
asp:TextBox
>
12
<
asp:Button
ID
="Button1"
runat
="server"
OnClick
="Button1_Click"
Text
="提取"
/>
13
<
br
/>
14
<
asp:TextBox
ID
="TextBox2"
runat
="server"
Height
="304px"
TextMode
="MultiLine"
Width
="524px"
></
asp:TextBox
></
div
>
15
</
form
>
16
</
body
>
17
</
html
>
18
共
1
页 第
1
页
上一页
1
下一页
相关的教程:
正则表达式
抓取见面
链接
Regex
收藏此教程
Currently.-0.05/5
-5
-4
-3
-2
-1
0
1
2
3
4
5
当前平均分:
0.0
(
0
次打分)
-5
-4
-3
-2
-1
0
1
2
3
4
5
推荐阅读
Javascript正则表达式简介
经典正则表达式
ASP.NET中常用的正则表达式(二)
ASP.NET中常用的17种正则表达式
.NET2.0隐形的翅膀,正则表达式搜魂者
经典正则表达式
常用的匹配正则表达式和实例
.NET2.0隐形的翅膀,正则表达式搜魂者
.NET2.0隐形的翅膀,正则表达式搜魂者
ASP.NET中常用的正则表达式(二)
添加评论
评论主题
您的大名
您的评论
验证码
评论列表
ASP.NET论坛
|
网站帮助
|
加入收藏
知识库搜索:
用户信息
欢迎您,游客。
登录
|
注册
为什么要注册?
马上加入GotAspx,建立自己的知识库,与大家分享您的知识库,还可获得丰厚积分奖励!
最新文章
C#中操作.INI文件(增,删,改)
ASP.NET中的五个内置对象的详解
安装VS2005时,Microsoft Document Explorer安装失败的解决方法
C#操作Word完全方法
通过ConfigurationSection来轻松地加载配置文件
String和enum的互相转换
成批更改数据库对象的所有者
web标准常见问题大全,让FireFox与IE兼容
热门文章
从零开始学ASP.NET(基础篇)
如何用VS2005制作Web安装程序
GridView 72般绝技(一)
使用InstallShield11.5部署Web程序
对初学者的建议:ASP.NET技术的学习顺序
CSS盒子模式(DIV布局快速入门)
用AJAX实现google输入自动完成的简单模拟
NHibernate 系列研究