日期:2014-05-18  浏览次数:21226 次

怎么获取HTMl源码
我想做个小程序 读取自己网站上面的一些信息,先捕获所有源码 怎么捕获 哪位大哥告诉下 先谢过了

------解决方案--------------------
// <summary>
/// 分析得到网页源代码
/// </summary>
/// <param name="url">目标网址</param>
/// <param name="bm">网址编码</param>

public static string GetHtml(string url, string bm)
{
WebResponse response = null;
Stream stream = null;
StreamReader reader = null;

WebRequest request = WebRequest.Create(url);
response = request.GetResponse();
stream = response.GetResponseStream();


try
{
reader = new StreamReader(stream, System.Text.Encoding.GetEncoding(bm));
}
catch (Exception ex)
{
reader = new StreamReader(stream, System.Text.Encoding.GetEncoding("GB2312")); 
}

string pagehtml = reader.ReadToEnd();


stream.Flush();
stream.Close();
response.Close();

return pagehtml;



}
------解决方案--------------------
我给的是win from开发下的.