php使用QueryList、Phantomjs教程文档

首先安装composer

Linux 平台

Linux 平台可以使用以下命令来安装:

# php -r “copy(‘https://install.phpcomposer.com/installer’, ‘composer-setup.php’);”

# php composer-setup.php

All settings correct for using ComposerDownloading…

Composer (version 1.6.5) successfully installed to: /root/composer.pharUse it: php composer.phar

移动 composer.phar,这样 composer 就可以进行全局调用:

# mv composer.phar /usr/local/bin/composer

切换为国内镜像:

# composer config -g repo.packagist composer https://packagist.phpcomposer.com

更新 composer:

# composer selfupdate

 

安装querylist

composer require jaeger/querylist

安装phantomjs

composer require jaeger/querylist-phantomjs  //PHP版本必须 >=7.0

下载对应你电脑系统的PhantomJS二进制文件,放到电脑任意路径,下面会用到这个路径,下载页面直达:http://phantomjs.org/download.html

 

示例代码

<?php

 

// 设置脚本超时

set_time_limit(0);

// 内存限制

ini_set(‘memory_limit’, ‘2014M’);

// 第三方库

require_once(‘./vendor/autoload.php’);

use QL\QueryList;

use QL\Ext\PhantomJs;

// 获取搜索结果

$book_name = ‘我的贴身校花’;

$ql = QueryList::getInstance();

$ql->use(PhantomJs::class,’/usr/local/bin/phantomjs’);

$html = $ql->browser(‘https://m.baidu.com/s?word=’.urlencode($book_name))->getHtml();

//$html = $ql->browser(‘https://www.whzh-cw.com/du/87792/65449347.html’)->getHtml();

var_dump($html);exit;

?>

 

 

运行后报错:Declaration of JonnyW\PhantomJs\DependencyInjection\ServiceContainer::load() should be compatible with Symfony\Component\DependencyInjection\Container::load($file)

修复:

进入vendor/jonnyw/php-phantomjs/src/JonnyW/PhantomJs/DependencyInjection

修改ServiceContainer.php

53行改为:public function load($file = null){

原创.转载请注明出处:www.tuike8.com
推课吧(tuike8) » php使用QueryList、Phantomjs教程文档

发表评论

提供最优质的资源集合

立即查看 了解详情