在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
public string GetHtml(string url, Encoding ed) { string Html = string.Empty;//初始化新的webRequst HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url); Request.KeepAlive = true; Request.ProtocolVersion = HttpVersion.Version11; Request.Method = "GET"; Request.Accept = "*/* "; Request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5"; Request.Referer = url; HttpWebResponse htmlResponse = (HttpWebResponse)Request.GetResponse(); //从Internet资源返回数据流 Stream htmlStream = htmlResponse.GetResponseStream(); //读取数据流 StreamReader weatherStreamReader = new StreamReader(htmlStream, ed); //读取数据 Html = weatherStreamReader.ReadToEnd(); weatherStreamReader.Close(); htmlStream.Close(); htmlResponse.Close(); //针对不同的网站查看html源文件 return Html; } public string GetHtml(string url) { return GetHtml(url, Encoding.UTF8); }
|
请发表评论