目前获取网页源码有几种方法:

1、WebClient下载页面
2、HttpWebRequest发请求获取
3、com组件xmlhttp获取

三者比较:WebClient代码最少,效率最慢;xmlhttp代码适中,效率最高,效率和前两者比较不是一个级别的,速度非常快

那我就简单介绍哈xmlhttp怎么获取网页源码

(1)引用com组件:Microsoft XML,v6.0

(2)引入命名空间:using MSXML2;

(3)代码:

        public static string GetHtmlCom(string url)
        {
            XMLHTTP60 xhttp = new XMLHTTP60();
            xhttp.open("get", url, false, null, null);
            xhttp.send();
            while (xhttp.readyState != 4)
                System.Threading.Thread.Sleep(1);
            return xhttp.responseText;
        }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-11-27
  • 2021-11-27
猜你喜欢
  • 2021-11-27
  • 2021-12-14
  • 2021-11-26
  • 2021-09-13
  • 2022-02-07
  • 2021-08-06
相关资源
相似解决方案