Web page
Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Net;
Using System.IO;
Namespace thief
{
Class Program
{
static void Main (string[] args)
{
try {
WebClient mywebclient = new WebClient ();
Mywebclient.credentials = credentialcache.defaultcredentials;//Gets or sets the network credentials used to authenticate requests to Internet resources.
byte[] Pagedata = Mywebclient.downloaddata ("http://www.163.com")//download data from the specified Web site
String pagehtml = Encoding.Default.GetString (pagedata); If you get the site page using GB2312, use this sentence
String pagehtml = Encoding.UTF8.GetString (pagedata); If you get the site page using UTF-8, use this sentence
Console.WriteLine (pagehtml);//What you get in the console input
using (StreamWriter sw = new StreamWriter ("c:\\test\\ouput.html"))//writes the acquired content to the text
{
Sw. Write (pagehtml);
}
Console.ReadLine (); Let the console pause, or it will flash past.
}
catch (WebException webEx) {
Console.WriteLine (WebEx.Message.ToString ());
}
}
}
}
Note: Content transferred from the Banyan tree under the blog of Yang