我需要使用远程代理服务器进行测试,但代理需要登录和密码才能进行授权。我尝试使用BrowserMobProxyServer
:
BrowserMobProxy bmp = new BrowserMobProxyServer();
bmp.start();
// This inject my remote proxy ip:port and login password.
bmp.autoAuthorization("111.111.111.111:8000", "l0gVal", "pasVal", AuthType.BASIC);
Proxy proxy = ClientUtil.createSeleniumProxy(bmp);
// I guess if info about this proxy already injected it should work without loin & password form but auth alert whenever appear(
proxy.setHttpProxy("111.111.111.111:8000");
proxy.setSslProxy("111.111.111.111:8000");
ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new ChromeDriver(options);
driver.get("https://whoer.net");
帮助我理解我的错误,我确定它可能,但是如何。 我得到了这个例外:
开启ChromeDriver 2.35.528157 (4429ca2590d6988c0745c24c8858745aaaec01ef)在港口30000上只有当地的 允许连接。 2018-04-26 11:45:22错误 o.l.p.impl.ClientToProxyConnection - (AWAITING_INITIAL)at at net.lightbody.bmp.util.BrowserMobHttpUtil.removeMatchingPort(BrowserMobHttpUtil.java:274) 〜[browsermob-core-2.1.0-beta-6.jar:na] at net.lightbody.bmp.filters.HttpsHostCaptureFilter.clientToProxyRequest(HttpsHostCaptureFilter.java:36) 〜[browsermob-core-littleproxy-2.1.0-beta-6.jar:na] at net.lightbody.bmp.filters.BrowserMobHttpFilterChain.clientToProxyRequest(BrowserMobHttpFilterChain.java:65) 〜[browsermob-core-littleproxy-2.1.0-beta-6.jar:na] at org.littleshoot.proxy.impl.ClientToProxyConnection.doReadHTTPInitial(ClientToProxyConnection.java:227) 〜[littleproxy-1.1.0-beta-bmp-12.jar:na] at org.littleshoot.proxy.impl.ClientToProxyConnection.readHTTPInitial(ClientToProxyConnection.java:191) 〜[littleproxy-1.1.0-beta-bmp-12.jar:na] at org.littleshoot.proxy.impl.ClientToProxyConnection.readHTTPInitial(ClientToProxyConnection.java:80) 〜[littleproxy-1.1.0-beta-bmp-12.jar:na] at org.littleshoot.proxy.impl.ProxyConnection.readHTTP(ProxyConnection.java:135) 〜[littleproxy-1.1.0-beta-bmp-12.jar:na] at org.littleshoot.proxy.impl.ProxyConnection.read(ProxyConnection.java:120) 〜[littleproxy-1.1.0-beta-bmp-12.jar:na] at org.littleshoot.proxy.impl.ProxyConnection.channelRead0(ProxyConnection.java:587) 〜[littleproxy-1.1.0-beta-bmp-12.jar:na] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) 〜[netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) [netty-all-4.0.36.Final.jar:4.0.36.Final] at org.littleshoot.proxy.impl.ProxyConnection $ RequestReadMonitor.channelRead(ProxyConnection.java:715) [littleproxy-1.1.0-beta-bmp-12.jar:na] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:277) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:264) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) [netty-all-4.0.36.Final.jar:4.0.36.Final] at org.littleshoot.proxy.impl.ProxyConnection $ BytesReadMonitor.channelRead(ProxyConnection.java:692) [littleproxy-1.1.0-beta-bmp-12.jar:na] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:962) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.nio.AbstractNioByteChannel $ NioByteUnsafe.read(AbstractNioByteChannel.java:131) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:485) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:399) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:371) [netty-all-4.0.36.Final.jar:4.0.36.Final] at io.netty.util.concurrent.SingleThreadEventExecutor $ 2.run(SingleThreadEventExecutor.java:112) [netty-all-4.0.36.Final.jar:4.0.36.Final] at java.lang.Thread.run(Thread.java:745)[na:1.8.0_101] 2018年4月26日 上午11:45:23 org.openqa.selenium.remote.ProtocolHandshake createSession 信息:检测到的方言:OSS
答案 0 :(得分:1)
另一个想法是使用custum浏览器配置文件;与Automatically download pdf in firefox gecko driver using selenium java中描述的类似。没有尝试过Chrome。至少你可以在你的代码中排除原因。