C# 如何在HtmlAlityPack中使用代理

C# 如何在HtmlAlityPack中使用代理,c#,html-agility-pack,http-proxy,C#,Html Agility Pack,Http Proxy,我需要使用带有HtmlAlityPack的代理。 我给我的应用程序加油链接。之后,我希望应用程序从代理地址获取url。例如101.109.44.157:8080 我搜索并发现: WebClient wc = new WebClient(); wc.Proxy = new WebProxy(host,port); var page = wc.DownloadString(url); 像这样使用它 RefURL = new Uri(refLink.Text); WebClient wc = ne

我需要使用带有HtmlAlityPack的代理。 我给我的应用程序加油链接。之后,我希望应用程序从代理地址获取url。例如101.109.44.157:8080

我搜索并发现:

WebClient wc = new WebClient();
wc.Proxy = new WebProxy(host,port);
var page = wc.DownloadString(url);
像这样使用它

RefURL = new Uri(refLink.Text);

WebClient wc = new WebClient();
wc.Proxy = new WebProxy("101.109.44.157:8080");
var page = wc.DownloadString(RefURL);

RefURL.ToString();
HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load(RefURL.ToString());

但它不起作用

代理IP没有响应,但您也没有在此代码行中传递web代理:

HtmlAgilityPack.HtmlDocument doc = web.Load(RefURL.ToString());
应该是:

HtmlAgilityPack.HtmlDocument doc = web.Load(RefURL.ToString(),"GET", webProxy);
第一步是查找新的代理IP列表,例如:

这些地址中的大多数会工作几个小时。退房如果代理是匿名的,则应该无法检测您的位置和IP

一旦您有了一个有效的代理IP和端口,您就可以创建webProxy对象,或者只需传递IP和端口

string RefURL = "https://www.whatismyip.com/";
string myProxyIP = "119.81.197.124"; //check this is still available
int myPort = 3128;
string userId = string.Empty; //leave it blank
string password = string.Empty;
try
{
    HtmlWeb web = new HtmlWeb();
    var doc = web.Load(RefURL.ToString(), myProxyIP, myPort, userId, password);
    Console.WriteLine(doc.DocumentNode.InnerHtml);
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

它不起作用!没有足够的说明。它无法通过代理服务链接代理没有响应。您需要新的代理IP列表。HtmlAgilityPack.HtmlDocument doc=web.LoadRefURL.ToString,IP,端口,,;谢谢你的重播。我收到此错误。System.dll中发生了类型为“System.Net.WebException”的未处理异常,无法连接到远程服务器需要新的代理服务器,如注释中所述。这些IP会定期进行blancklisted,因此必须进行更改。我使用了一个新的代理。它可以与firefox或ie配合使用。