我正在学习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