在AWS Lambda Java函数中执行Phantomjs时出错

时间:2018-03-13 15:14:50

标签: java linux phantomjs aws-lambda illegalstateexception

我在Phantomjs(无头浏览器)的帮助下使用Eclipse进行爬行来创建和调用AWS Lambda函数进行爬网。在执行Lambda函数时,它会抛出非法状态异常错误。可执行文件位于 / var / task / phantomjs 。我甚至尝试对该可执行文件应用 chmod 命令,但仍显示相同的错误。代码如下

Runtime r = Runtime.getRuntime();
try {
    Process p = r.exec("chmod 755 /var/task/phantomjs");
} catch (IOException e1) {
    e1.printStackTrace();
}

DesiredCapabilities dCaps = new DesiredCapabilities();
dCaps.setJavascriptEnabled(true);
dCaps.setCapability("takesScreenshot", false);      

dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,"/var/task/phantomjs");
WebDriver driver = new PhantomJSDriver(dCaps);

错误如下:

The driver is not executable: /var/task/phantomjs: java.lang.IllegalStateException
java.lang.IllegalStateException: The driver is not executable: /var/task/phantomjs
    at com.google.common.base.Preconditions.checkState(Preconditions.java:534)
    at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:140)
    at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:245)
    at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:181)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:105)
    at com.amazonaws.lambda.rss.RSS.handleRequest(RSS.java:77)
    at com.amazonaws.lambda.rss.RSS.handleRequest(RSS.java:1)

如果你能提前解决这个问题,那将会非常有帮助,谢谢你。

0 个答案:

没有答案