[C #] GetHtmlSource,

Source: Internet
Author: User

[C #] GetHtmlSource,

Key code:

/// <Summary> /// obtain the HTML source code of the webpage // </summary> /// <param name = "url"> link eg: http://www.baidu.com/ </Param> // <param name = "charset"> Encoding eg: Encoding. UTF8 </param> // <returns> HTML source code </returns> public static string GetHtmlSource (string url, Encoding charset) {string _ html = string. empty; try {HttpWebRequest _ request = (HttpWebRequest) WebRequest. create (url); HttpWebResponse _ response = (HttpWebResponse) _ request. getResponse (); using (Stream _ stream = _ response. getResponseStream () {using (StreamReader _ reader = new StreamReader (_ stream, charset) {_ html = _ reader. readToEnd () ;}} catch (WebException ex) {using (StreamReader sr = new StreamReader (ex. response. getResponseStream () {_ html = sr. readToEnd () ;}} catch (Exception ex) {_ html = ex. message;} return _ html ;}

Test code:

        public static void GetHtmlSourceTest()        {            string _url = "http://www.baidu.com/";            string _htmlSource = HttpWebRequestUtilsV2.GetHtmlSource(_url, Encoding.UTF8);            Console.WriteLine(_htmlSource);        }

Test results:

. Csharpcode ,. csharpcode pre {font-size: small; color: black; font-family: Las LAS, "Courier New", courier, monospace; background-color: # ffffff; /* white-space: pre ;*/}. csharpcode pre {margin: 0em ;}. csharpcode. rem {color: #008000 ;}. csharpcode. kwrd {color: # 0000ff ;}. csharpcode. str {color: #006080 ;}. csharpcode. op {color: # effecc0 ;}. csharpcode. preproc {color: # cc6633 ;}. csharpcode. asp {background-color: # ffff00 ;}. csharpcode. html {color: #800000 ;}. csharpcode. attr {color: # ff0000 ;}. csharpcode. alt {background-color: # f4f4f4; width: 100%; margin: 0em ;}. csharpcode. lnum {color: #606060 ;}
What is pc?

PC is a computer
A notebook is also called a computer.
Tablets are also called computers
PC (personal computer), derived from IBM's first desktop computer model PC in 1978, before which there was an Apple II personal computer. Personal computers that can run specific functions independently. Personal computers do not need to share the processing, disks, printers, and other resources of other computers. Today, the term PC refers to all personal computers, such as desktop computers, notebook computers, or personal computers compatible with IBM systems.

What is pc

1. PC.

2. I personally think it may also mean surfing the Internet. In Korean, "PC networking" means Internet cafes,

This is also possible if the author of this article is also Han serverplaygroup.

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.