【问题标题】:PhantomJS when calling from PHP return blank page else running fine从 PHP 调用时 PhantomJS 返回空白页,否则运行良好
【发布时间】: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


【解决方案1】:

经过大量测试和好的建议。我找到了解决这个问题的方法。

问题与 PHP 版本有关,PHP 版本 5.5.28 给出空白输出。将版本更改为 5.5.9 后,输出开始显示在我的网页上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    • 2015-06-10
    相关资源
    最近更新 更多