java写了一个爬虫 seleuinm+phantomjs 出现下面这种错误,百度google各种都找不到问题.
试验多台机器 其中只有两台死活启动不了
[root@app_test tools]# java -jar t-1.0.jar 二月 22, 2017 2:28:30 下午 org.openqa.selenium.phantomjs.PhantomJSDriverService <init> 信息: executable: /home/tools/phantomjs-2.1.1-linux-x86_64/bin/phantomjs 二月 22, 2017 2:28:30 下午 org.openqa.selenium.phantomjs.PhantomJSDriverService <init> 信息: port: 65326 二月 22, 2017 2:28:30 下午 org.openqa.selenium.phantomjs.PhantomJSDriverService <init> 信息: arguments: [--ignore-ssl-errors=true, --ssl-protocol=tlsv1, --cookies-file=test.cookies, --disk-cache=true, --local-to-remote-url-access=true, --web-security=false, --webdriver=65326, --webdriver-logfile=/home/tools/phantomjsdriver.log] 二月 22, 2017 2:28:30 下午 org.openqa.selenium.phantomjs.PhantomJSDriverService <init> 信息: environment: {} [INFO - 2017-02-22T06:28:30.928Z] GhostDriver - Main - running on port 65326 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: 'app_test', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-431.el6.x86_64', java.version: '1.8.0_102' Driver info: driver.version: PhantomJSDriver at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144) at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:116) at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:105) at robot.TestSelenium.getPhantomjs(TestSelenium.java:43) at robot.TestSelenium.main(TestSelenium.java:49) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) Caused by: java.lang.IllegalStateException: The process has not exited yet therefore no result is available ... at org.apache.commons.exec.DefaultExecuteResultHandler.getException(DefaultExecuteResultHandler.java:76) at org.openqa.selenium.os.UnixProcess.checkForError(UnixProcess.java:171) at org.openqa.selenium.os.CommandLine.checkForError(CommandLine.java:185) at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:177) at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:166) at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.execute(PhantomJSCommandExecutor.java:78) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644) ... 15 more
最后发现原来是 hosts文件配置有问题
如果host中没有定义127.0.0.1 localhost 就会报上面问题
添加localhost 127.0.0.1 关系