111,126
社区成员
发帖
与我相关
我的任务
分享
实在是 不知道为什么了
/// <summary>
/// 取得网页源码
/// </summary>
/// <param name="url">网页地址,eg: "http://www.yongfa365.com/" </param>
/// <param name="charset">网页编码,eg: Encoding.UTF8</param>
/// <returns>返回网页源文件</returns>
public static string GetHtmlSource(string url, Encoding charset)
{
//处理内容
string html = "";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, charset);
html = reader.ReadToEnd();
stream.Close();
}
catch (Exception e)
{
}
return html;
}