我正在學習PhantomJS和PHP-PhantomJS。我想通過一個腳本PhantomJS。通過PHP-PhantomJS將腳本傳遞給PhantomJS的正確方法?
目前我想這一點:
$client->getEngine()->addOption('/Applications/myWebApp/js/phantomtest.js');
$request = $client->getMessageFactory()->createRequest('http://www.jonnyw.me/', 'GET');
$response = $client->getMessageFactory()->createResponse();
$client->send($request, $response);
if ($response->getStatus() === 200) {
echo $response->getContent();
}
我得到一個空$response
對象調用$client->send($request, $response)
後回來。
Here's the contents of my test script ('phantomtest.js'):
var page = require('webpage').create();
page.open('http://www.jonnyw.me', function(status) {
console.log("Status: " + status);
if(status === "success") {
page.render('example.png');
}
phantom.exit();
});
看起來很有趣,但我會盡早使用反引號 – pguardiario
@pguardiario,對此使用反引號的正確方法是什麼? – VikR
'<?php \'/ usr/bin/phantomjs /path/to/script.js \'?>'或[exec](http://php.net/manual/en/function.exec.php) – Vaviloff