C# 代理访问页面并获取数据
生活随笔
收集整理的這篇文章主要介紹了
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/";?
轉載于:https://www.cnblogs.com/yishilin/p/7503801.html
總結
以上是生活随笔為你收集整理的C# 代理访问页面并获取数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 函数的定义
- 下一篇: Discrete Logging POJ