1. <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">截取到网页数据是js加载完以后的</span>
  1. <span style="white-space:pre">    </span>    HtmlWeb webClient = new HtmlWeb();
  2. string _url = "http://news.baidu.com/";
  3. HtmlAgilityPack.HtmlDocument html1 = webClient.Load(_url);//是你需要解析的url
  4. var end3 = html1.Encoding.BodyName;//获取页面编码格式
  5. string _htmlSource = GetHtmlSource(_url, System.Text.Encoding.GetEncoding(end3));//还是需要设置一次编码格式避免乱码 调用<span style="font-family: Arial, Helvetica, sans-serif;">GetHtmlSource方法</span>
    1. public static string GetHtmlSource(string url, Encoding charset)
    2. {
    3. string _html = string.Empty;
    4. try
    5. {
    6. HttpWebRequest _request = (HttpWebRequest)WebRequest.Create(url);
    7. HttpWebResponse _response = (HttpWebResponse)_request.GetResponse();
    8. using (Stream _stream = _response.GetResponseStream())
    9. {
    10. using (StreamReader _reader = new StreamReader(_stream, charset))
    11. {
    12. _html = _reader.ReadToEnd();
    13. }
    14. }
    15. }
    16. catch (WebException ex)
    17. {
    18. using (StreamReader sr = new StreamReader(ex.Response.GetResponseStream()))
    19. {
    20. _html = sr.ReadToEnd();
    21. }
    22. }
    23. catch (Exception ex)
    24. {
    25. _html = ex.Message;
    26. }
    27. return _html;
    28. }

最新文章

  1. JavaScript填坑史
  2. Linux head和tail命令
  3. phalcon: 获取参数的方法
  4. fil_space_t
  5. js实现图片上传及预览----------------------&gt;&gt;兼容ie6-8 火狐以及谷歌
  6. linux内核交互,设备驱动控制管理接口
  7. 在Windows环境下部署Axis2/C服务
  8. Android开源项目(一)
  9. c语言数组应用--统计随机数并打印直方图
  10. springboot学习笔记-1 第一个springboot示例
  11. Screen tearing
  12. win7 点IE浏览器无法打开
  13. 三, 练习 python索引 (list和tuple)
  14. Koa,React和socket.io
  15. python爬虫快递查询系统(源码)
  16. VLC框架分析
  17. elcipse 安装lombok插件解决 @Slf4j 等找不到log变量问题
  18. Oracle数据库中的数据出错的解决办法
  19. [leetcode]122. Best Time to Buy and Sell Stock II 最佳炒股时机之二
  20. (轉)Equal height boxes with CSS

热门文章

  1. WebView中shouldOverrideUrlLoading和onPageStarted方法的区别
  2. c++ 获取文件图标,类型名称,属性 SHGetFileInfo
  3. 探索Redis设计与实现14:Redis事务浅析与ACID特性介绍
  4. SPOJ_QTREE系列题解
  5. HDU 6610 Game — 2019第三场杭电多校 1008题
  6. Objective-C UIWebview JS 交互
  7. RFC6241 NETCONF
  8. activiti7业务表示Businesskey
  9. POI教程
  10. Python matplotlib 交互模式