The Get URL request page HTML code (rpm)

Get the HTML code page based on the URL request

/// <Summary>
/// Get the HTML code
/// </ Summary>
/// <param name = "URL"> link address </ param>
/// <param name = "encoding"> coding type </ param>
/// <Returns> </ Returns>
public static String GetHtmlStr (URL String, String encoding)
{
String htmlStr = "";
IF (! String.IsNullOrEmpty (URL))
{
the WebRequest Request = the WebRequest.Create (url); // instantiate WebRequest object
WebResponse response = request.GetResponse (); // Create a WebResponse object
stream datastream = response.GetResponseStream (); // Create a stream object
encoding EC = Encoding.Default;
IF (encoding == "the UTF8")
{
EC = Encoding.UTF8;
}
the else IF (encoding == "Default")
{
= Encoding.Default EC;
}
the StreamReader Reader the StreamReader new new = (Datastream, EC);
htmlStr reader.ReadToEnd = (); // read data
reader.Close ();
datastream.Close ();
response.Close ();
}
htmlStr return;
}
2, download site pictures

/// <summary>
/// 下载网站图片
/// </summary>
/// <param name="picUrl"></param>
/// <returns></returns>
public string SaveAsWebImg(string picUrl)
{
string result = "";
string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"/File/"; //目录
try
{
if (!String.IsNullOrEmpty(picUrl))
{
Random rd = new Random();
DateTime nowTime = DateTime.Now;
string fileName = nowTime.Month.ToString() + nowTime.Day.ToString() + nowTime.Hour.ToString() + nowTime.Minute.ToString() + nowTime.Second.ToString() + rd.Next(1000, 1000000) + ".jpeg";
WebClient webClient = new WebClient();
webClient.DownloadFile(picUrl, path + fileName);
result = fileName;
}
}
catch { }
return result;
}


 

Guess you like

Origin www.cnblogs.com/LiZhongZhongY/p/10938915.html