ASP. NET, C # implement web page thief Program

Source: Internet
Author: User
In ASP, thieves use XMLHTTP objects. Recently, I have been learning. net, the WebClient class is displayed, so I changed the program used for thieves and used ASP. net, C # to achieve, the program write is relatively simple, the purpose is to serve as a valuable author, hope to discuss with you to make it more perfect, next, I will make it possible to obtain the specified content on the webpage according to the settings. The following is the program section, including the ASP. net source program on 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 website thieves
// * Written by smile 2005-12-11
// * URL: http://blog.hnce.net
// * Email: hedongyang@gmail.com QQ: 5364083
//*
//************************************** *********************
Void page_load (Object sender, eventargs E)
{
String strurl = "http://blog.hnce.net"; // URL of the webpage to be retrieved

WebClient mywebclient = new WebClient (); // create a WebClient instance mywebclient

// Obtain or set the network creden。 used to authenticate requests to Internet resources.
Mywebclient. Credentials = credentialcache. defaultcredentials;

// Download data from the resource and return a byte array. (Add @ because there is a "/" symbol in the middle of the URL)
Byte [] pagedata = mywebclient. downloaddata (strurl );

// You only need to use one of the following two sentences at a time. The function is the same as that used to convert character sets.
// String result = encoding. Default. getstring (pagedata );
// If you use gb2312 to retrieve the website page, use this sentence.
String result = encoding. utf8.getstring (pagedata );
// Use this sentence if the UTF-8 is used to get the website page
// Because my blog uses UTF-8 encoding, so here I use this sentence
Response. Write (result); // display the obtained content on the web page
}
</SCRIPT>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>

<Body>
</Body>
</Html>

C # (getwebcontent. CS)

/*
**************************************** *****************
*
* Use C # To implement the website thief Program
* Written by smile
* URL: 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 ());
}
}
}

Download Code
/Files/Maxie/getwebcontent.rar

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.