zoukankan      html  css  js  c++  java
  • C# 代理访问页面并获取数据

    本来在找IWebDriver使用代理的方法,偶然获知这种的,记录并且共享

     1 WebProxy proxyObject = new WebProxy("125.31.19.26", 80);//str为IP地址 port为端口号 代理类
     2 HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://ip.chemdrug.com/"); // 61.183.192.5
     5 Req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; QQWubi 133; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; CIBA; InfoPath.2)";
     6 Req.Proxy = proxyObject; //设置代理 
     8 Req.Method = "GET";
     9 HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();
    10 string StringSub = "";
    11 string OkStr = "";
    12 Encoding code = Encoding.GetEncoding("gb2312");
    13 using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), code))
    14 {
    16    string str1 = sr.ReadToEnd();//获取得到的网址html返回数据,这里就可以使用某些解析html的dll直接使用了,比如htmlpaser 
    17 
    18 }

    selenium 

     1 ChromeOptions options = new ChromeOptions();
     2 Proxy proxy = new Proxy();
     3 proxy.Kind = ProxyKind.Manual;
     4 proxy.IsAutoDetect = false;
     5 proxy.HttpProxy =
     6 proxy.SslProxy = "125.31.19.26:80";
     7 options.Proxy = proxy;
     8 options.AddArgument("ignore-certificate-errors");
     9 var chromedriver = new ChromeDriver(options);
    10  chromedriver.Url = "http://www.whatismyip.com.tw/";
  • 相关阅读:
    jchdl
    jchdl
    jchdl
    jchdl
    jchdl
    jchdl
    jchdl
    UVa 437 (变形的LIS) The Tower of Babylon
    UVa 1025 (动态规划) A Spy in the Metro
    UVa 10129 (并查集 + 欧拉路径) Play on Words
  • 原文地址:https://www.cnblogs.com/yishilin/p/7503801.html
Copyright © 2011-2022 走看看