gpt4 book ai didi

java - PhantomjsDriver 不适用于 Windows 和 Linux

转载 作者:搜寻专家 更新时间:2023-10-31 19:55:30 24 4
gpt4 key购买 nike

我有一个应用程序使用 Selenium Webdriver 从站点获取一些信息。它适用于 FirefoxDriver 和 ChromeDriver,但当我尝试切换到 PhantomJSDriver 时,我遇到了一些困难。

  1. 在 Windows 机器上,它正常启动,然后立即开始一遍又一遍地吐出以下行:

Jan 05, 2014 7:28:43 PM org.apache.http.impl.client.DefaultRequestDirector tryEx ecute INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond

这可能会重复数百次,持续约 10 分钟,直到最终加载页面;有时它甚至根本无法加载它。

  1. 在 Linux 机器上,它尝试启动,然后返回以下内容:

Exception in thread "thread1" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'pangolin', ip: '128.238.32.20', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-39-generic', java.version: '1.7.0' Driver info: driver.version: PhantomJSDriver at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:115) at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:107) at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:96) Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'pangolin', ip: '128.238.32.20', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-39-generic', java.version: '1.7.0' Driver info: driver.version: PhantomJSDriver at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527) ... 7 more Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:16050/status] to be available after 20002 ms at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104) at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163) ... 9 more Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143) at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79) ... 10 more Caused by: java.util.concurrent.TimeoutException at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:258) at java.util.concurrent.FutureTask.get(FutureTask.java:119) at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130) ... 11 more

我做错了什么?我已经阅读了很多关于 Phantomjs 为什么比其他驱动程序快得多的文章,并且真的很想使用它,但是如果加载每个页面需要 10 分钟,那显然是不可行的。

我正在运行 Selenium WebDriver 2.38.0 版和 Phantomjs 1.9.2 版。

非常感谢您,背景

编辑澄清一下,我不认为这与我的代码有任何关系; Linux 上的错误在我尝试启动 PhantomJS 驱动程序的行中抛出,如下所示。

   DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
phantombinary//"/home/p/phantomjs-1.9.2-linux-x86_64/bin/phantomjs"
);

// Launch driver (will take care and ownership of the phantomjs process)
WebDriver driver = new PhantomJSDriver(caps);
System.out.println("starting driver");

最佳答案

如果它在 Linux 上仍然不适合你,请尝试下面的代码,它在 Mac 上对我有用。

capabilities.setCapability("phantomjs.binary.path", "path of phantom binary/phantomjs")

关于java - PhantomjsDriver 不适用于 Windows 和 Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20941518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com