【发布时间】:2017-03-05 02:06:18
【问题描述】:
我正在学习 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();
}
在调用 $client->send($request, $response) 后,我得到了一个空的 $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,为此使用反引号的正确方法是什么?
-
<?php `/usr/bin/phantomjs /path/to/script.js` ?>或 exec -
确保你抓住了价值:
<?php $response = `phantomjs /path/to/script.js` ?> -
我不知道你能做到。
标签: web-scraping phantomjs php-phantomjs