从我的Java应用程序
private static DesiredCapabilities buildCapabilities() {
String userAgent = "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1";
System.setProperty("phantomjs.page.settings.userAgent", userAgent);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("takesScreenshot", true);
capabilities.setCapability("phantomjs.page.settings.userAgent", userAgent);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, PHANTOMJS_EXECUTABLE_PATH_PROPERTY);
return capabilities;
}
PhantomJSDriver mainDriver = new PhantomJSDriver(buildCapabilities());
mainDriver.manage().window().maximize();
mainDriver.get("https://www.mycommerce.com/");
Thread.sleep(20000);
我正在尝试通过PhantomJS 1.9.8
访问以下页面http://www.mycommerce.com/在我的Windows 10机器上一切正常但在CentOS 5.8上我只得到一个跟随错误和屏幕:
[INFO - 2016-01-02T15:31:30.888Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created:
[ERROR - 2016-01-02T15:31:32.591Z] Session [] - page.onError - msg: ReferenceError: Can't find variable: jQuery
[ERROR - 2016-01-02T15:31:32.591Z] Session ] - page.onError - stack:
(anonymous function) (https://www.mycommerce.com/:100)
[ERROR - 2016-01-02T15:31:32.602Z] Session [] - page.onError - msg: ReferenceError: Can't find variable: jQuery
[ERROR - 2016-01-02T15:31:32.602Z] Session [- page.onError - stack:
(anonymous function) (https://www.mycommerce.com/:229)
[ERROR - 2016-01-02T15:31:32.606Z] Session [] - page.onError - msg: ReferenceError: Can't find variable: jQuery
[ERROR - 2016-01-02T15:31:32.606Z] Session [] - page.onError - stack:
(anonymous function) (https://www.mycommerce.com/:406)
(anonymous function) (https://www.mycommerce.com/:414)
[ERROR - 2016-01-02T15:31:32.620Z] Session [] - page.onError - msg: ReferenceError: Can't find variable: jQuery
[ERROR - 2016-01-02T15:31:32.620Z] Session [] - page.onError - stack:
(anonymous function) (https://www.mycommerce.com/:818)
(anonymous function) (https://www.mycommerce.com/:826)
[ERROR - 2016-01-02T15:31:32.662Z] Session [] - page.onError - msg: ReferenceError: Can't find variable: jQuery
[ERROR - 2016-01-02T15:31:32.663Z] Session [] - page.onError - stack:
如何解决?
答案 0 :(得分:0)
@alexanoid,似乎某些广告拦截器扩展程序在您的浏览器中启用,禁止页面完全呈现。在我的机器上尝试使用广告拦截器,它会产生与上面附加的图像相同的图像。 因此,您应该停用广告/扩展程序并尝试再次运行该脚本。 希望这能解决问题。