phantomjs不使用nodejs

时间:2016-07-07 22:32:21

标签: node.js phantomjs

我已尝试过在互联网上找到的所有内容,但我无法在我的ubuntu 14.04服务器上运行phantomjs。

这是我的nodejs代码段:

phantom.create("--web-security=no", "--ignore-ssl-errors=yes",function(ph) {
  return ph.createPage(function(page) {
    return page.open(htmlfilepath, function(status) {
        page.paperSize = { format: 'A4', orientation: 'portrait', border: '1cm' };

        page.render(pdffilepath, function(){
          ph.exit();
        });
      });
    });
  });

代码在我的本地系统(mac os x)上运行正常。我使用brew在本地系统上安装了phantomjs。

在我的服务器上,我使用apt-get安装了phantomjs,并且在运行代码时出现以下错误:

phantom stderr: Fontconfig warning: ignoring UTF-8: not a valid region tag 

以下是调试跟踪:

phantom stderr: Fontconfig warning: ignoring UTF-8: not a valid region tag                                                                                                   [47/205]                                                                                                          
phantom stderr: 2016-07-08T02:12:50 [DEBUG] CookieJar - Created but will not store cookies (use option '--cookies-file=<filename>' to enable persisten cookie storage)       [45/205]                                                           
phantom stderr: 2016-07-08T02:12:50 [DEBUG] Phantom - execute: Configuration                                                                                                 [43/205]
2016-07-08T02:12:50 [DEBUG]      0 objectName : ""                                                                                                                           [42/205]
2016-07-08T02:12:50 [DEBUG]      1 cookiesFile : ""                                                                                                                          [41/205]
2016-07-08T02:12:50 [DEBUG]      2 diskCacheEnabled : "false"                                                                                                                [40/205]                                                                                                   
phantom stderr: 2016-07-08T02:12:50 [DEBUG]      3 maxDiskCacheSize : "-1"                                                                                                   [38/205]
2016-07-08T02:12:50 [DEBUG]      4 ignoreSslErrors : "true"                                                                                                                  [37/205]
2016-07-08T02:12:50 [DEBUG]      5 localToRemoteUrlAccessEnabled : "false"                                                                                                   [36/205]
2016-07-08T02:12:50 [DEBUG]      6 outputEncoding : "UTF-8"                                                                                                                  [35/205]
2016-07-08T02:12:50 [DEBUG]      7 proxyType : "http"                                                                                                                        [34/205]
2016-07-08T02:12:50 [DEBUG]      8 proxy : ":1080"                                                                                                                           [33/205]
2016-07-08T02:12:50 [DEBUG]      9 proxyAuth : ":"                                                                                                                           [32/205]
2016-07-08T02:12:50 [DEBUG]      10 scriptEncoding : "UTF-8"                                                                                                                 [31/205]
2016-07-08T02:12:50 [DEBUG]      11 webSecurityEnabled : "false"                                                                                                             [30/205]
2016-07-08T02:12:50 [DEBUG]      12 offlineStoragePath : ""                                                                                                                  [29/205]
2016-07-08T02:12:50 [DEBUG]      13 offlineStorageDefaultQuota : "-1"                                                                                                        [28/205]
2016-07-08T02:12:50 [DEBUG]      14 printDebugMessages : "true"                                                                                                              [27/205]
2016-07-08T02:12:50 [DEBUG]      15 javascriptCanOpenWindows : "true"                                                                                                        [26/205]
2016-07-08T02:12:50 [DEBUG]      16 javascriptCanCloseWindows : "true"                                                                                                       [25/205]
2016-07-08T02:12:50 [DEBUG]      17 sslProtocol : "sslv3"                                                                                                                    [24/205]
2016-07-08T02:12:50 [DEBUG]      18 sslCertificatesPath : ""                                                                                                                 [23/205]
                                                                                                                                                                         [22/205]
phantom stderr: 2016-07-08T02:12:50 [DEBUG]      19 webdriver : ":"                                                                                                          [21/205]
2016-07-08T02:12:50 [DEBUG]      20 webdriverLogFile : ""                                                                                                                    [20/205]
2016-07-08T02:12:50 [DEBUG]      21 webdriverLogLevel : "INFO"                                                                                                               [19/205]
2016-07-08T02:12:50 [DEBUG]      22 webdriverSeleniumGridHub : ""                                                                                                            [18/205]
2016-07-08T02:12:50 [DEBUG] Phantom - execute: Script & Arguments                                                                                                            [17/205]
2016-07-08T02:12:50 [DEBUG]      script: "/home/ubuntu/api/node_modules/phantom/shim.js"                                                                                     [16/205]
2016-07-08T02:12:50 [DEBUG]      0 arg: "57128"                                                                                                                              [15/205]
2016-07-08T02:12:50 [DEBUG]      1 arg: "127.0.0.1"                                                                                                                          [14/205]
2016-07-08T02:12:50 [DEBUG] Phantom - execute: Starting normal mode                                                                                                          [13/205]
                                                                                                                                                                         [12/205]
phantom stderr: 2016-07-08T02:12:50 [DEBUG] WebPage - setupFrame ""                                                                                                          [11/205]
                                                                                                                                                                         [10/205]
phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/fs.js" QMap(("mode", QVariant(QString, "r") ) )                                                    [9/205]
                                                                                                                                                                          [8/205]
phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/system.js" QMap(("mode", QVariant(QString, "r") ) )                                                [7/205]
                                                                                                                                                                          [6/205]
phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/_coffee-script.js" QMap(("mode", QVariant(QString, "r") ) )                                        [5/205]
                                                                                                                                                                          [4/205]
phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/package.json" QMap(("mode", QVariant(QString, "r") ) )                            [3/205]
                                                                                                                                                                          [2/205]
phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/./lib/coffee-script/coffee-script.js" QMap(("mode", QVariant(QString, "r") ) )    [1/205]
                                                                                                                                                                          [0/205]
phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/./lib/coffee-script/./lexer.js" QMap(("mode", QVariant(QString, "r") ) )  

phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/./lib/coffee-script/././rewriter.js" QMap(("mode", QVariant(QString, "r") ) )  

phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/./lib/coffee-script/././helpers.js" QMap(("mode", QVariant(QString, "r") ) )  

phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/./lib/coffee-script/./parser.js" QMap(("mode", QVariant(QString, "r") ) )  

phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/./lib/coffee-script/./helpers.js" QMap(("mode", QVariant(QString, "r") ) )  

phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/./lib/coffee-script/./nodes.js" QMap(("mode", QVariant(QString, "r") ) )  

phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/./lib/coffee-script/././scope.js" QMap(("mode", QVariant(QString, "r") ) )  

phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/./lib/coffee-script/./././helpers.js" QMap(("mode", QVariant(QString, "r") ) )  

phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/./lib/coffee-script/././lexer.js" QMap(("mode", QVariant(QString, "r") ) )  

phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/../coffee-script/./lib/coffee-script/./././rewriter.js" QMap(("mode", QVariant(QString, "r") ) )  

phantom stderr: 2016-07-08T02:12:50 [DEBUG] FileSystem - _open: ":/modules/webpage.js" QMap(("mode", QVariant(QString, "r") ) )  

phantom stderr: 2016-07-08T02:12:50 [DEBUG] WebPage - setupFrame "<!--framePath //<!--frame0-->-->" 
2016-07-08T02:12:50 [DEBUG] WebPage - updateLoadingProgress: 10 

phantom stderr: 2016-07-08T02:12:50 [DEBUG] WebPage - updateLoadingProgress: 11 

phantom stderr: 2016-07-08T02:12:50 [DEBUG] Network - Resource request error: 6 ( "SSL handshake failed" ) URL: "https://d1fxtkz8shb9d2.cloudfront.net/sockjs-0.3.min.js" 

phantom stderr: 2016-07-08T02:12:50 [DEBUG] WebPage - updateLoadingProgress: 100 

phantom stderr: 2016-07-08T02:12:50 [DEBUG] WebPage - setupFrame "<!--framePath //<!--frame1-->-->" 

phantom stderr: 2016-07-08T02:12:50 [DEBUG] WebPage - updateLoadingProgress: 10 

phantom stderr: 2016-07-08T02:12:50 [DEBUG] WebPage - updateLoadingProgress: 11 

phantom stderr: 2016-07-08T02:12:50 [DEBUG] Network - Resource request error: 6 ( "SSL handshake failed" ) URL: "https://d1fxtkz8shb9d2.cloudfront.net/sockjs-0.3.min.js" 

phantom stderr: 2016-07-08T02:12:50 [DEBUG] WebPage - updateLoadingProgress: 100 

有关如何修复此错误的任何帮助都将受到高度赞赏。感谢。

1 个答案:

答案 0 :(得分:0)

事实证明,在安装较新版本的phantomjs后,此问题已得到解决。我试过1.9.7和1.9.8,这两个都是我系统上面的错误。安装phantomjs-2.1.1后,问题自动解决。

以下步骤用于安装phantomjs-2.1.1:

cd /usr/local/share
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo tar xjf phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs