2013-11-21 17 views
0

首先,我使用節點phantomJS bridge需要指定一個配置文件到PhantomJS節點橋

PhantomJS是v1.9.2的

節點是v0.10.15

我的問題是,我不能設置一個配置文件來phantomJS節點。

基本上我的代碼有云:

console.log(settings);
var phantom = require("node-phantom"); 

phantom.create(function (err, ph){ 

    ph.createPage(function (err, page){ 

     page.set("settings.config", "./myConfig.json"); 

     page.get("settings", function(err, settings){ 
      console.log(settings); 
     }); 

    }); 
}); 

我只獲得默認設置:

{ XSSAuditingEnabled: false, 
    javascriptCanCloseWindows: true, 
    javascriptCanOpenWindows: true, 
    javascriptEnabled: true, 
    loadImages: true, 
    localToRemoteUrlAccessEnabled: false, 
    userAgent: 'Mozilla/5.0 (Macintosh; PPC Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.2 Safari/534.34', 
    webSecurityEnabled: true } 

我試過很多東西分配我的配置的文件phantomJS或我的網頁實例,沒有運氣。

set('settings.config') on phantom or phant,但沒有任何結果。

我也試過,因爲它在Doc的說:

phantom.create("--config=./path/to/config.json", function (err, ph){ 
    ... 
}); 

錯誤,需要一個函數作爲第一個參數。所以我試過了:

phantom.create(function (err, ph){ 
    ... 
}, {"--config":"./path/to/config.json"}); 

還是沒有運氣。

我錯過了什麼嗎?

謝謝你的時間。

編輯:我沒有使用正確的文檔(-_-)...

因此,與node-phantom(我終於用一個),這樣做的正確方法是:

phantom.create(callback, { parameters : {"config" : "path/to/file.json" }}); 

我可以證實,它現在正在工作。

回答

2

據我所看到的,你是不是在找合適的文件...主要有兩種套餐是PhantomJS上的Node.js:

我看到你正在使用節點幻影

var phantom = require("node-phantom"); 

但你試圖用一個幻影功能。因爲它是寫在幻影的文檔:

屬性不能獲得/直接設置,而是使用頁。get('version',callback)或p.page.set('viewportSize',{width:640,height:480})等等。嵌套對象可以通過在鍵中包含點來訪問,例如p.page.set (「settings.loadImages」,虛假)

但似乎沒有成爲包節點幻像您使用的是字面上相同功能。

希望它有幫助! OMG!

+2

OMG!我是個白癡...... 'node-phantom'的等價物是: 'phantom.create(callback,{parameters:{「config」:「path/to/file.json」}}); ' 我可以證實,它現在正在工作。 – YoannM