This article describes the C # access to the HTML source code method, share to everyone for your reference. Here's how:
The key code is as follows:
The code is as follows:
<summary>
Get Web page HTML source code
</summary>
<param name= "url" > Links eg:http://www.baidu.com/</param>
<param name= "CharSet" > Encode eg:encoding.utf8</param>
<returns>html Source </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;
}
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
C # get Web page HTML Source instance
This address: http://www.paobuke.com/develop/c-develop/pbk23440.html
Related content implementation of a state machine SuperSocket Getting Started--telnet server and client request processing detailed parsing C # multithreaded synchronization events and wait handles nine Gongge algorithm based on C # code all equals 4.
C # How to implement Ping method summary C # serialization and deserialization (Serialize,deserialize) Example of C # convert a number to a byte array method using the params keyword of C # to implement a variable number of parameter parameters example
C # get Web page HTML Source instance