/// <Summary>
/// Obtain the html source file of the webpage
/// </Summary>
/// <Param name = "url"> webpage address </param>
/// <Param name = "encodingStr"> webpage file encoding string </param>
/// <Returns> html source file </returns>
# Region GetPageSource
Public static string GetPageSource (string url, string encodingStr)
{
HttpWebResponse res = null;
String strResult = "";
Try
{
HttpWebRequest req = (HttpWebRequest) WebRequest. Create (url );
// Req. Method = "POST ";
Req. KeepAlive = true;
Req. ContentType = "application/x-www-form-urlencoded ";
Req. Accept = "text/Html, application/xhtml + XML, application/xml; q = 0.9, */*; q = 0.8 ";
Req. UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-CN; rv: 1.9.2.8) Gecko/20100722 Firefox/3.6.8 ";
Res = (HttpWebResponse) req. GetResponse ();
StreamReader reader = new StreamReader (res. GetResponseStream (), Encoding. GetEncoding (encodingStr ));
StrResult = reader. ReadToEnd ();
Reader. Close ();
}
Catch
{
}
Finally
{
If (res! = Null)
{
Res. Close ();
}
}
Return strResult;
}