使用 Chrome 驱动程序的 C# Selenium 代理身份验证 [英] C# Selenium Proxy Authentication with Chrome Driver
问题描述
我正在为代理使用以下代码.但是,当chrome启动时,会弹出弹窗并锁定程序.
I am using the following code for the proxy. however, when chrome starts, pop-up window will pop up and the program will be locked.
public async void StartDriver(string proxy)
{
var proxys = new Proxy();
ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
ChromeOptions chromeOptions = new ChromeOptions();
bool flag = !string.IsNullOrEmpty(proxy);
if (flag)
{
proxys.Kind = ProxyKind.Manual;
proxys.IsAutoDetect = false;
proxys.SslProxy = proxy;
chromeOptions.Proxy = proxys;
}
driver = new ChromeDriver(chromeDriverService, chromeOptions, TimeSpan.FromMinutes(10));
await Task.Delay(2000);
}
我试过 http 或 ssl 一样...
I tried http or ssl the same...
StartDriver("88.55.66.77:8080");
或者
StartDriver("http://username:pass@88.55.66.77:8080");
我无法使用某种代理启动浏览器.
I could not start a browser with a kind of proxy.
我想要一个自动输入用户名和密码的代码.我不想要 autoitx3.dll.
I want a code that automatically enters the username and password. I don't want autoitx3.dll.
有没有办法启动安全代理?
is there a way to start a secure proxy?
谢谢.
推荐答案
有没有办法启动安全代理?
is there a way to start a secure proxy?
有一个.您需要使用代理设置创建 chrome 扩展.
There's one. You need to create a chrome extension with proxy settings.
manifest.json
{
"version": "0.1.0",
"manifest_version": 2,
"name": "%NAME IT AS YOU WANT%",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
},
"minimum_chrome_version":"22.0.0"
}
background.js
//note that it's a JS code. You can use any additional code to do anything :)
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "%HOST%",
port: parseInt(%PORT%)
},
bypassList: ["foobar.com"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "%USERNAME%",
password: "%PASSWORD%"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
将其打包为存档.例如 yourExt.dat
Pack it as an archive. For instance yourExt.dat
var proxy = "yourExt.dat";
var options = new ChromeOptions();
options.AddExtension(proxy);
var driver = new ChromeDriver(options);
这篇关于使用 Chrome 驱动程序的 C# Selenium 代理身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!