使用带有htmlagilitypack代理 [英] using a proxy with htmlagilitypack

查看:172
本文介绍了使用带有htmlagilitypack代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了这个问题,但没有发现任何东西,我一直在寻找,基本上我想使用htmlagilitypack代理,我有代码之前做到这一点,但失去了它,这里是我到目前为止的代码,这是工作。但我计时我自己出的一个程序我正在和需要启用代理服务器。

 私人无效的button1_Click(对象发件人,EventArgs E)
{
StringBuilder的输出=新的StringBuilder();
串生=htt​​p://www.google.com
HtmlWeb webGet =新HtmlWeb();
webGet.UserAgent =Mozilla的/ 5.0(视窗; U; Windows NT的5.1; EN-US; rv中:1.9.2)的Gecko / 20100115火狐/ 3.6;
变种文件= webGet.Load(生);


}


解决方案

使用 HtmlWeb.Load过载()使用代理服务器。有两种过载签名:

 的HTMLDocument负载(URL字符串,字符串的方法,WebProxy代理的NetworkCredential的凭证); 
的HTMLDocument负载(URL字符串,字符串的ProxyHost,诠释proxyPort,字符串userid,字符串密码);



我没有使用代理在我的代码的第一手经验,但是我希望这工作。


I searched this question but didn't find anything that I was looking for, basically I want to use a proxy with htmlagilitypack, I had the code to do it before but lost it, here is the code I have so far, which is working. but I timed my self out on a program I was making and need to enable proxies.

    private void button1_Click(object sender, EventArgs e)
    {
        StringBuilder output = new StringBuilder();
        string raw = "http://www.google.com";
        HtmlWeb webGet = new HtmlWeb();
        webGet.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6";
        var document = webGet.Load(raw);


    }

解决方案

Use an overload of HtmlWeb.Load() that uses proxies. There are two overload signatures:

HtmlDocument Load(string url, string method, WebProxy proxy, NetworkCredential credentials);
HtmlDocument Load(string url, string proxyHost, int proxyPort, string userId, string password);

I don't have any first-hand experience using proxies in my code but I'd expect this to work.

这篇关于使用带有htmlagilitypack代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆