所以我使用:https://github.com/jonnnnyw/php-phantomjs,Phantom JS的PHP包装器。我已经按照说明使用composer安装了这个包:
php composer require jonnyw/php-phantomjs:2.*
我正在使用Codeigniter,所以我必须在类定义之前声明它的用法:
use JonnyW\PhantomJs\Client;
class WebScrape extends CI_Controller { require 'vendor/autoload.php'; ..}然后我使用了下面的代码:
$client = Client::getInstance();
$client->setPhantomJs('/var/www/PhantomJS/vendor/bin/');
$request = $client->getMessageFactory()->createRequest('GET', 'http://php.net/manual/en/ref.image.php#56144');
$response = $client->getMessageFactory()->createResponse();
// Send the request
$client->send($request, $response);
echo $response->getStatus();
if($response->getStatus() === 200) {
// Dump the requested page content
echo $response->getContent();
}我没有收到任何错误,但是$response->getStatus();返回给我0。我不知道如何调试,因为我也没有PHP错误。有人知道如何解决这个问题吗?
发布于 2014-07-03 07:26:46
对于正在努力解决此问题的任何人,请执行以下操作:
卸载phantomjs
sudo apt-get remove --auto-remove phantomjs全新安装
cd /usr/local/share
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2
sudo tar xjf phantomjs-1.9.7-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/bin/phantomjs在$client = Client::getInstance();下添加以下行
$client->setPhantomJs('/usr/local/share/phantomjs');现在,确保在use JonnyW\PhantomJs\Client;之前使用require 'vendor/autoload.php';
应该行得通:
https://stackoverflow.com/questions/24541000
复制相似问题