【发布时间】:2015-10-04 03:55:19
【问题描述】:
我正在使用 PHP 调用 phantomjs 脚本,但它返回空白输出。虽然它在控制台上运行良好。
这是我的 JS 文件:
var page = new WebPage();
var system = require('system');
page.open("https://www.groupon.com/goods", function(){
var events = page.evaluate(function(){
return $('.deal-card').map(function(e){
return '* ' + this.innerText
}).toArray().join('\n');
});
console.log('Upcoming Events in Oxfordshire:');
console.log(events);
phantom.exit();
});
这是我的 PHP
$script = "C:/phantomjs-2.0.0/bin/price1.js";
$response = exec("C:/phantomjs-2.0.0/bin/phantomjs $script", $output);
print_r($response);
Print_r(implode(",,",$output));
【问题讨论】:
-
我复制了代码,它可以工作。也许它与您的 phantomjs 配置有关。
-
还是安全问题。
-
感谢@winner_joiner 我已经在我的系统上重新安装了最新的 phantomjs 和 XAMPP。
-
你是对的,因为在这些新安装之前一切都很好
-
谢谢@winner_joiner,问题出在 PHP 版本上,我使用的是 5.5.28,这会出现问题。现在我更改为 PHP 5.5.9,修复了它。
标签: php web-scraping phantomjs