我正在使用我的Rails应用程序中的屏幕捕获方案的phantomjs 2.1.1。 这是我的js:
var page = new WebPage(),
address, output, actual_height;
var system = require('system');
if (system.args.length < 2 || system.args.length > 3) {
phantom.exit();
} else {
console.log('Else');
address = system.args[1];
output = system.args[2];
console.log(address);
console.log(output);
page.viewportSize = { width: 1024, height: 768 };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
console.log('Success...');
/* Some code here */
}
});
}
我在命令行中运行应用程序时遇到此错误:
(cd /var/www/html/project/MyProject/vendor/javascripts/phantomjs_linux/bin; ./phantomjs /var/www/html/project/MyProject/vendor/javascripts/indicator_screenshots.js http://xx.xx.xxx.xx/users/1/reports/50148 /var/www/html/project/MyProject/public/indicator_screenshots/50148.png)
显示此错误:
无法加载地址!
通过一些R&amp; D,我从我的bin文件夹中运行命令:
./phantomjs --debug=yes --ignore-ssl-errors=true --ssl-protocol=any --web-security=true /var/www/html/project/MyProject/vendor/javascripts/indicator_screenshots.js http://xx.xx.xxx.xx/users/1/reports/50148 /var/www/html/project/MyProject/public/indicator_screenshots/50148.png
这是我的日志:
2016-10-12T06:29:38 [DEBUG] CookieJar - 已创建但不会存储 cookies(使用选项'--cookies-file ='来启用持久性 cookie存储)2016-10-12T06:29:38 [DEBUG]将“http”代理设置为:“” :1080 2016-10-12T06:29:38 [DEBUG]幻像 - 执行:配置 2016-10-12T06:29:38 [DEBUG] 0 objectName:“”2016-10-12T06:29:38 [DEBUG]
1 cookiesFile:“”2016-10-12T06:29:38 [DEBUG]
2 diskCacheEnabled:“false”2016-10-12T06:29:38 [DEBUG]
3 maxDiskCacheSize:“ - 1”2016-10-12T06:29:38 [DEBUG]
4 diskCachePath:“”2016-10-12T06:29:38 [DEBUG]
5 ignoreSslErrors:“true”2016-10-12T06:29:38 [DEBUG]
6 localUrlAccessEnabled:“true”2016-10-12T06:29:38 [调查]
7 localToRemoteUrlAccessEnabled:“false”2016-10-12T06:29:38 [DEBUG]
8 outputEncoding:“UTF-8”2016-10-12T06:29:38 [DEBUG]
9 proxyType:“http”2016-10-12T06:29:38 [DEBUG]
10代理:“:1080”2016-10-12T06:29:38 [DEBUG]
11 proxyAuth:“:” 12 scriptEncoding:“UTF-8”2016-10-12T06:29:38 [DEBUG]
13 webSecurityEnabled:“true”2016-10-12T06:29:38 [DEBUG]
14 offlineStoragePath:“”2016-10-12T06:29:38 [DEBUG]
15 localStoragePath:“”2016-10-12T06:29:38 [DEBUG]
16 localStorageDefaultQuota:“ - 1”2016-10-12T06:29:38 [DEBUG]
17 offlineStorageDefaultQuota:“ - 1”2016-10-12T06:29:38 [DEBUG]
18 printDebugMessages:“true”2016-10-12T06:29:38 [DEBUG]
19 javascriptCanOpenWindows:“true”2016-10-12T06:29:38 [DEBUG]
20 javascriptCanCloseWindows:“true”2016-10-12T06:29:38 [DEBUG]
21 sslProtocol:“any”2016-10-12T06:29:38 [DEBUG]
22 sslCiphers: “ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA -AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:DHE-RSA-AES256 -SHA:AES128-GCM-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:RC4-SHA:RC4,MD5" 2016-10-12T06:29:38 [调查]
23 sslCertificatesPath:“”2016-10-12T06:29:38 [DEBUG]
24 sslClientCertificateFile:“”2016-10-12T06:29:38 [DEBUG]
25 sslClientKeyFile:“”2016-10-12T06:29:38 [DEBUG]
26 sslClientKeyPassphrase:“”2016-10-12T06:29:38 [调查]
27 webdriver:“:”2016-10-12T06:29:38 [DEBUG]
28 webdriverLogFile:“”2016-10-12T06:29:38 [DEBUG]
29 webdriverLogLevel:“INFO”2016-10-12T06:29:38 [DEBUG]
30 webdriverSeleniumGridHub:“” 2016-10-12T06:29:38 [DEBUG]幻影 - 执行:Script&amp;参数 2016-10-12T06:29:38 [DEBUG]剧本: “/var/www/html/project/MyProject/vendor/javascripts/indicator_screenshots.js” 2016-10-12T06:29:38 [DEBUG] 0 arg: “http://xx.xx.xxx.xx/users/1/reports/50148”2016-10-12T06:29:38 [DEBUG] 1 arg: “/var/www/html/project/MyProject/public/indicator_screenshots/50148.png” 2016-10-12T06:29:38 [DEBUG] Phantom - 执行:启动正常模式 2016-10-12T06:29:38 [DEBUG] WebPage - setupFrame“” 2016-10-12T06:29:38 [DEBUG] FileSystem - _open:“:/ module / fs.js” QMap((“模式”,QVariant(QString,“r”)))2016-10-12T06:29:38 [DEBUG] FileSystem - _open:“:/ module / system.js”QMap((“mode”, QVariant(QString,“r”)))2016-10-12T06:29:38 [DEBUG] FileSystem - _open:“:/ mododules / webpage.js”QMap((“mode”,QVariant(QString,“r”))) 的否则 的 http://xx.xx.xxx.xx/users/1/reports/50148 的 /var/www/html/project/MyProject/public/indicator_screenshots/50148.png 2016-10-12T06:29:38 [DEBUG] WebPage - updateLoadingProgress:10 2016-10-12T06:30:38 [DEBUG]网络 - 资源请求错误: QNetworkReply :: NetworkError(TimeoutError)(“套接字操作定时 out“)网址:”http://xx.xx.xxx.xx/users/1/reports/50148“
您可以在 Else (粗体)后面的上述日志中查看地址和输出值,这些值以js形式写入console.log。 根据日志,我在 page.open 时遇到错误。 请帮助解决这个问题..