首页
最近更新
热门教程
ASP.NET
开发语言
开发环境
AJax教程
控件开发
统计报表
数据库
Web服务
安装部署
HTML教程
Javascript
XML教程
Community Server
NHibernate
书籍推荐
常用工具
实用代码
教程全文搜索
首页
>>
ASP.NET
.NET2.0抓取网页全部链接
添加人:
admin
添加时间:2007-08-11 阅读次数:1231
收藏此教程
效果图
后台代码:
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
0
1
2
3
4
5
6
7
8
9
10
当前平均分:
0.0
(
0
次打分)
0
1
2
3
4
5
6
7
8
9
10
推荐阅读
Javascript正则表达式简介
经典正则表达式
ASP.NET中常用的正则表达式(二)
ASP.NET中常用的17种正则表达式
.NET2.0隐形的翅膀,正则表达式搜魂者
经典正则表达式
常用的匹配正则表达式和实例
.NET2.0隐形的翅膀,正则表达式搜魂者
.NET2.0隐形的翅膀,正则表达式搜魂者
ASP.NET中常用的正则表达式(二)
添加评论
评论主题
您的大名
您的评论
验证码
评论列表
ASP.NET论坛
|
网站帮助
|
加入收藏
知识库搜索:
用户信息
欢迎您,游客。
登录
|
注册
为什么要注册?
是否经常遇到以前解决过的问题,现在却忘了解决办法了?这里有一个好方法
本类热门
从零开始学ASP.NET(基础篇)
ASP.NET 2.0轻松实现数据库应用开发
ASP.NET 程序中常用的三十三种代码
GridView 72般绝技(一)
对初学者的建议:ASP.NET技术的学习顺序
单点登录在ASP.NET上的简单实现
ASP.NET数据库编程快速入门之技术慨述
ASP.NET 2.0中构造个性化网页
本类最新
第二篇:简单的介绍subsonic工具 SubStage
xml 文件的不同读取方式
介绍SubSonic【转】
ASP.NET访问XML的例子
WEB开发者版本级别
基于.NET2.0的System.Net.Mail发送邮件Demo
Asp.Net 文件操作基类(读取,删除,批量拷贝,批量删除,写入)
c#生成与 追加xml