简体   繁体   English

C#硒chromedriver代理身份验证

[英]C# selenium chromedriver proxy auth

im writing a automation tool in visual studio with c#. 即时通讯使用C#在Visual Studio中编写自动化工具。

im using selenium with chromedriver. 我在chromedriver中使用硒。 i need proxy user pass auth for my session. 我需要代理用户通过身份验证才能进行会话。 But i try so many times and so many sources but didnt work. 但是我尝试了很多次,有很多资料,但是没有用。

How to basicly user pass ip port proxy for my chromedriver session. 基本上,用户如何为我的chromedriver会话传递ip端口代理。 Thanks for help. 感谢帮助。

There are a couple of options. 有两种选择。

Configuring a proxy using ChromeOptions and org.openqa.selenium.Proxy 使用ChromeOptionsorg.openqa.selenium.Proxy配置代理

If you want the solution to be easily portable to run on other systems, you can try configuring a proxy using ChromeOptions and org.openqa.selenium.Proxy . 如果您希望该解决方案易于移植以在其他系统上运行,则可以尝试使用ChromeOptionsorg.openqa.selenium.Proxy配置代理。 There will be some additional methods in here to configure your proxy, but we need to know what type of proxy and type of authentication is supported. 这里将提供一些其他方法来配置您的代理,但是我们需要知道支持什么类型的代理和身份验证类型。

// Add the WebDriver proxy capability.
Proxy proxy = new Proxy();
proxy.setHttpProxy("myhttpproxy:3337");
options.setCapability("proxy", proxy);

// Add a ChromeDriver-specific capability.
ChromeDriver driver = new ChromeDriver(options);

Create a new chrome profile with proxy configuration 使用代理配置创建新的Chrome配置文件

Alternatively, you could create a profile for chrome with the proxy configured and tell chrome driver to work with that. 另外,您可以使用已配置的代理为chrome创建配置文件,并告诉chrome驱动程序使用该配置文件。 This would be difficult, if not impossible, to port to other systems without manual setup, unless you containerized it, but that's out of scope here. 除非您将其容器化,否则如果没有手动设置,将很难(即使不是不可能)移植到其他系统,但这不在本文讨论范围之内。

As of chrome 71, head to chrome settings at chrome://settings/ and choose Manage other people. 从chrome 71开始,请访问chrome://settings/ chrome设置,然后选择管理其他人。 Create a new person to represent your proxy profile. 创建一个新人来代表您的代理配置文件。 Configure the proxy using the browser the way you normally would for manually connecting. 使用浏览器配置代理,方法与通常手动连接的方式相同。

Locate the path to your profile, something like: C:\\Users\\<username>\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1 if you're on windows. 找到个人资料的路径,例如: C:\\Users\\<username>\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1 You can easily find by navigating to chrome://version/ and looking for Profile Path 您可以通过导航到chrome://version/并查找Profile Path轻松找到

Utilize ChromeOptions to pass the option for setting the user data directory for chrome on startup 利用ChromeOptions传递用于在启动时为Chrome设置用户数据目录的选项

ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");

Some snippets pulled from documentation for chromedriver chromedriver文档中提取了一些片段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM