2016-05-02 15 views
-1

我有phantomjs和casperjs在web服務器上工作。我有一個網頁,上面有一個表格,表格中有兩個字段(名稱和電子郵件地址)。將多個變量從php傳遞給casperjs

我需要輸入'name'和'email'作爲變量到我的casper腳本中。從閱讀

Pass parameter from php to casperjs/phantomjs

http://phantomjs.org/api/system/property/platform.html

我明白你需要把VAR系統和變參,但所有的荷蘭似乎是雙重給我。

PHP代碼

$name = $_POST['user_input']; 
$email = $_POST['user_input']; 
putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs"); 
exec('/usr/local/bin/casperjs hello.js $name $email 2>&1',$output); 

print_r($output); 

casperjs代碼

var system = require('system'); 
var args = system.args; 
var name = args 
var email = args 

var casper = require('casper').create({ 
    verbose: true, 
}); 
casper.start('website url'); 



casper.then(function() { 
    casper.wait(5000); 
     this.echo("wait for 5 seconds."); 

}); 
casper.then(function() { 

    this.sendKeys('#firstname', name); 
    this.sendKeys('#thereemail', email); 
    this.click('.button'); 

從它,我需要得到雙方進入一個參數長相,然後分裂他們,但我怎麼會去這樣做?

編輯:該方法貼是行不通的

+1

可能的重複[如何將變量和數據從PHP傳遞到JavaScript?](http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to -javascript) –

+0

[如何通過命令行將變量傳遞給CasperJS腳本?](http://stackoverflow.com/questions/21765178/how-to-pass-a-variable-toa-a- casperjs腳本-透命令行) – Vaviloff

回答