- <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">截取到网页数据是js加载完以后的</span>
- <span style="white-space:pre"> </span> HtmlWeb webClient = new HtmlWeb();
- string _url = "http://news.baidu.com/";
- HtmlAgilityPack.HtmlDocument html1 = webClient.Load(_url);
- var end3 = html1.Encoding.BodyName;
- string _htmlSource = GetHtmlSource(_url, System.Text.Encoding.GetEncoding(end3));
- public static string GetHtmlSource(string url, Encoding charset)
- {
- string _html = string.Empty;
- try
- {
- HttpWebRequest _request = (HttpWebRequest)WebRequest.Create(url);
- HttpWebResponse _response = (HttpWebResponse)_request.GetResponse();
- using (Stream _stream = _response.GetResponseStream())
- {
- using (StreamReader _reader = new StreamReader(_stream, charset))
- {
- _html = _reader.ReadToEnd();
- }
- }
- }
- catch (WebException ex)
- {
- using (StreamReader sr = new StreamReader(ex.Response.GetResponseStream()))
- {
- _html = sr.ReadToEnd();
- }
- }
- catch (Exception ex)
- {
- _html = ex.Message;
- }
- return _html;
- }
-
相关文章:
-
2022-01-03
-
2022-02-22
-
2021-12-25
-
2022-12-23
-
2022-01-24
-
2021-11-05
猜你喜欢
-
2021-11-01
-
2021-12-05
-
2022-12-23
-
2021-10-25
-
2021-10-19
相关资源
-
下载
2021-06-05
-
下载
2023-02-09
-
下载
2023-01-04
-
下载
2022-12-26