小偷程序之网页分块筛选
ASP.Net、C#实现网页小偷程序
asp.net、c#实现网页小偷程序
在asp中实现小偷是使用xmlhttp对象,最近在学习.net时看到了webclient类,于是将过去用来做小偷的程序改了一下,使用asp.net、c#来实现,程序写的比较简单,目的是为了起到抛砖引玉的作者,希望能与各位一起探讨,使之更加完善,下一步我将使之实现根据设置可以获取网页中指定的内容。以下是程序部分,包括在web页中的asp.net的源程序和c#中的源程序。
asp.net (getwebcontent.aspx)
<%@ page language="c#" %>
<%@ import namespace="system.net" %>
<%@ import namespace="system.text" %>
<script runat=server>
//***********************************************************
//*
//* 使用asp.net实现网站小偷的程序
//* written by 笑笑 2005-12-11
//* 网址:http://blog.hnce.net
//* email:hedongyang@gmail.com qq:5364083
//*
//***********************************************************
void page_load(object sender , eventargs e)
{
string strurl="http://blog.hnce.net"; //欲获取的网页地址
webclient mywebclient=new webclient(); //创建webclient实例mywebclient
//获取或设置用于对向 internet 资源的请求进行身份验证的网络凭据。
mywebclient.credentials=credentialcache.defaultcredentials;
//从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)
byte[] pagedata=mywebclient.downloaddata(strurl);
//以下两句每次只要使用一条即可,功能是一样是用来转换字符集,根据获取网站页面的字符编码选择
//string result=encoding.default.getstring(pagedata);
//如果获取网站页面采用的是gb2312,则使用这句
string result=encoding.utf8.getstring(pagedata);
//如果获取网站页面采用的是utf-8,则使用这句
//因为我的博客使用了utf-8编码,所以在这里我使用这句
response.write(result); //在web页中显示获取的内容
}
</script>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
</body>
</html>
c# (getwebcontent.cs)
/*
*********************************************************
*
* 使用c#实现网站小偷的程序
* written by 笑笑 2005-12-11
* 网址:http://blog.hnce.net
* email:hedongyang@gmail.com qq:5364083
*
*********************************************************
*/
using system;
using system.net;
using system.text;
class getwebcontent
{
public static void main()
{
try
{
webclient mywebclient = new webclient();
mywebclient.credentials = credentialcache.defaultcredentials;
byte[] pagedata = mywebclient.downloaddata("http://blog.hnce.net");
string pagehtml = encoding.utf8.getstring(pagedata);
console.writeline(pagehtml);
}
catch (webexception webex)
{
console.write(webex.tostring());
}
}
}
下面为使用正则实现筛选
privatestring ClHtml(string html)
{
string str ="";
string strtemp ="";
string[] s;
int n =0;
Regex r =new Regex(@"weathertitle([\w\W]*?)text/javascript");
MatchCollection ms = r.Matches(html);
foreach (Match m in ms)
{
try
{
str = m.Groups[1].Value;
str ="<div class=\""+ str;
str = str.Replace("<script type='", "");
}
catch { }
}
//Regex rr = new Regex(@"title([\w\W]*?)</td>");
//MatchCollection mss = rr.Matches(str);
//int dd = 0;
//int tell = 0;
//int tell1 = 0;
//string nametxt = "";
//string telltxt = "";
//foreach (Match mm in mss)
//{
// try
// {
// strtemp = mm.Groups[1].Value;
// strtemp = strtemp.Replace("\t", "").Replace("\n", "");
// dd = strtemp.LastIndexOf("\">");
// nametxt = strtemp.Substring(0, dd).Replace("=\"", "");
// tell = strtemp.LastIndexOf("电话:");
// tell1 = strtemp.LastIndexOf("</span>");
// telltxt = strtemp.Substring(tell, tell1 - tell).Replace("电话:", "");
// no = no + 1;
// label2.Text = no.ToString() + "条";
// textBox2.Text = textBox2.Text + nametxt + " " + telltxt + "\r\n";
// }
// catch { }
//}
//if (ms.Count == 0)
//{
// n = 1;
//}
return n;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!