通常,我们给selenium设置代理的方式很简单,网上也有很多示例。
但是我们如何给selenium设置有账号密码验证的代理呢,在Selenium的SDK中并没有这个入口,也没有集成这几个参数。
于是,我查找了网上的一些资料,发现python的案例是很多的,C#没有😶没有。。(好好的C#非得让做点爬虫的事情😂)为了完成任务,我只能是想办法转译成C#代码。分享出来,希望可以帮到同样处境的.Net同僚们。
转译后的代码如下:
这是核心代码,其中的plugin_path是生成的文件路径,当然大家可以自己换路径。其他的代码不用动。
public string create_proxy_auth_extension(string proxy_host,string proxy_port,string proxy_username,string proxy_password,string scheme= "http")
{
string plugin_path = Environment.CurrentDirectory+ "/SelectniumProxy/Proxy";
if (!Directory.Exists(plugin_path))
{
Directory.CreateDirectory(plugin_path);
}
string filePath = plugin_path + $"/{proxy_username}_{proxy_password}@{proxy_host}_{proxy_port}.zip";
string manifest_json = "{\"version\": \"1.0.