具有企业代理身份验证的Chrome无头浏览器不起作用 [英] Chrome headless browser with corporate proxy authetication not working
问题描述
我正在尝试运行安装在公司代理后面的Chrome无头浏览器.我尝试了下面的代码.但无法通过.
I am trying to run a Chrome headless browser sitting behind a corporate proxy. I tried below code. But unable to pass through it.
public class HeadlessChrome
{
WebDriver driver;
@Test
public void createChromeDriverHeadless() throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "D:\\LocalData\\workspace\\Drivers and Libraries\\driver\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("http://user:pwd@server:port");
proxy.setSslProxy("http://user:pwd@server:port");
// chromeOptions.setCapability("proxy", proxy);
chromeOptions.addArguments("--proxy-server=user:pwd@server:port");
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("start-maximized");
driver = new ChromeDriver(chromeOptions);
driver.get("http://seleniumhq.org");
Thread.sleep(5000);
System.out.println("Title : " + driver.getTitle());
assertTrue(driver.findElement(By.id("q")).isDisplayed());
driver.quit();
}
}
请帮帮我.
推荐答案
如果您没有使用 headless
,则可以使用以下链接中的方法
If you were not using headless
you could have used the approach in below link
但目前不允许无头扩展名.所以现在您的选择是添加另一个代理
But with headless extension are currently not allowed. So now your option is add another proxy
chrome -> (intermediate proxy w/o auth) -> corporate proxy w/ auth -> internet
一种选择是使用 polipo
https://www.irif.fr/~jch/software/polipo/
具有以下配置
parentAuthCredentials=username:password
parentProxy=corporateproxy:port
然后使用
chromeOptions.addArguments("--proxy-server=http://polipoproxy:port");
默认设置为 127.0.0.1:8123
,不要在polipo配置中覆盖.
The default would be 127.0.0.1:8123
in don't override in polipo config.
您可以使用的其他选项
-
使用鱿鱼代理代替polipo
Use squid proxy instead of polipo
使用python或node或您喜欢的任何其他语言编写自己的代理转发器
Write your own proxy forwarder using python or node or any other language you are comfortable with
这篇关于具有企业代理身份验证的Chrome无头浏览器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!