asp.net, C # to implement the Web Thief program

Source: Internet
Author: User
Tags character set
Asp.net| Program | Web page | Thief program

asp.net, C # to implement the Web Thief program
In the implementation of the ASP thief is the use of XMLHTTP objects, recently in learning. Net saw the WebClient class, so the past used to do the thief program changed, using ASP.net, C # to achieve, the program is written relatively simple, the purpose is to play the author, I hope to discuss with you, make it more perfect, next I will make it implementation according to the settings can get the content specified in the Web page. The following are part of the program, including the ASP.net source program in the Web page and the source program in C #.

asp.net (getwebcontent.aspx)

<%@ Page language= "C #"%>
<%@ Import namespace= "System.Net"%>
<%@ Import namespace= "System.Text"%>
<script runat=server>
//***********************************************************
//*
* Use ASP.net to implement the Web site Thieves program
* Written by Smile 2005-12-11
* Website: http://blog.hnce.net
* Email:hedongyang@gmail.com qq:5364083
//*
//***********************************************************
void Page_Load (Object sender, EventArgs e)
{
String strurl= "Http://blog.hnce.net"; The address of the Web page you want to get

WebClient mywebclient=new WebClient (); Create WebClient instance Mywebclient

Gets or sets the network credentials used to authenticate requests to Internet resources.
Mywebclient.credentials=credentialcache.defaultcredentials;

Downloads data from a resource and returns a byte array. (add @ Because there is a "/" symbol in the middle of the URL)
Byte[] Pagedata=mywebclient.downloaddata (strURL);

The following two sentences can be used one at a time, the function is the same is used to convert character set, according to get the Site page character encoding selection
String result=encoding.default.getstring (Pagedata);
If you get the site page using GB2312, use this sentence
String result=encoding.utf8.getstring (Pagedata);
If you get the site page using UTF-8, use this sentence
Because my blog uses the UTF-8 code, so here I use this sentence
Response.Write (Result); Show what gets in a Web page
}
</Script>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </title>

<body>
</body>

C # (GetWebcontent.cs)

/*
*********************************************************
*
* Use C # to implement the Web site Thieves program
* Written by Smile 2005-12-11
* Website: 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 ());
}
}
}


asp.net, C # Web thief source program package download



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.