selenium-chromedriver - 使用 Chrome 驱动程序的 C# Selenium 代理身份验证
问题描述
我正在为代理使用以下代码。但是,当chrome启动时,会弹出弹出窗口并锁定程序。
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 ...
StartDriver("88.55.66.77:8080");
或者
StartDriver("http://username:pass@88.55.66.77:8080");
我无法使用某种代理启动浏览器。
我想要一个自动输入用户名和密码的代码。我不想要 autoitx3.dll。
有没有办法启动安全代理?
谢谢你。
解决方案
有没有办法启动安全代理?
有一个。您需要使用代理设置创建 chrome 扩展。
清单.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"
}
背景.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
var proxy = "yourExt.dat";
var options = new ChromeOptions();
options.AddExtension(proxy);
var driver = new ChromeDriver(options);
推荐阅读
- swift - iOS Swift WebRTC - 无法设置远程报价 sdp:无法设置远程视频描述发送参数
- python-3.x - tktable模块安装问题。_tkinter.TclError:无效的命令名称“表”
- java - 从 Java 中的多模块项目生成数据流模板
- csv - 仅导入更新的列谷歌脚本
- electron - electron-builder,在windows中,如何配置可以退出安装过程?
- python - 使用 python 从 3d .stl 文件中查找 2D 横截面中的材料和空气
- c# - 从 Api 返回 CSV,而不将所有数据库结果放入字符串
- javascript - ReactJs,在全局状态更改时丢失子组件本地状态
- xamarin.forms - Xamarin 表单集合视图在数据加载时显示骨架
- java - CRUD 中的更新返回 null id