仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1316|回复: 9
打印 上一主题 下一主题

[学习教程] ASP.NET教程之.NET2.0抓取网页全体链接

[复制链接]
透明 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:30:48 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
就安全性而言,Java已经远远低于VB.NET,更无法与安全性著称的C#相比。最终效果

背景代码
以下为援用的内容:
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Text.RegularExpressions;
usingSystem.Net;
usingSystem.IO;
usingSystem.Collections;

publicpartialclass_Default:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!IsPostBack)
{

}

}


protectedvoidButton1_Click(objectsender,EventArgse)
{
TextBox2.Text="";
stringweb_url=this.TextBox1.Text;//"http://blog.csdn.net/21aspnet/"
stringall_code="";
HttpWebRequestall_codeRequest=(HttpWebRequest)WebRequest.Create(web_url);
WebResponseall_codeResponse=all_codeRequest.GetResponse();
StreamReaderthe_Reader=newStreamReader(all_codeResponse.GetResponseStream());
all_code=the_Reader.ReadToEnd();
the_Reader.Close();
ArrayListmy_list=newArrayList();
stringp=@"http://([w-]+.)+[w-]+(/[w-./?%&=]*)?";
Regexre=newRegex(p,RegexOptions.IgnoreCase);
MatchCollectionmc=re.Matches(all_code);
for(inti=0;i<=mc.Count-1;i++)
{
bool_foo=false;
stringname=mc.ToString();
foreach(stringlistinmy_list)
{
if(name==list)
{
_foo=true;
break;
}
}//过滤
if(!_foo)
{
TextBox2.Text+=name+"
";
}
}
}
}

前台
以下为援用的内容:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>抓取网页一切链接</title>

</head>
<body>
<formid="form1"runat="server">
<div>
<asp:TextBoxID="TextBox1"runat="server"Width="481px"></asp:TextBox>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="提取"/>
<br/>
<asp:TextBoxID="TextBox2"runat="server"Height="304px"TextMode="MultiLine"Width="524px"></asp:TextBox></div>
</form>
</body>
</html>


前几天同学问我学习方向的问题。有点想法,不知道对不对,怕误导同学,现在“开源一下”。注:括号内是我现在整理的时填加上的。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-9 18:38

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表