jaeger / querylist-phantomjs
QueryList 插件:使用 PhantomJS 采集 JavaScript 动态渲染的页面。(无头 WebKit)使用 PhantomJS 采集 JavaScript 动态渲染的页面
4.0.1
2017-09-30 13:33 UTC
Requires
- php: >=7.0
- jonnyw/php-phantomjs: 4.*
Requires (Dev)
- jaeger/querylist: dev-master
This package is auto-updated.
Last update: 2024-09-09 16:54:55 UTC
README
QueryList 插件:使用 PhantomJS 采集 JavaScript 动态渲染的页面。(无头 WebKit)
QueryList插件: 使用PhantomJS采集JavaScript动态渲染的页面。
PhantomJS: http://phantomjs.org QueryList:https://github.com/jae-jae/QueryList
QueryList4 安装
composer require jaeger/querylist-phantomjs
API
- browser($url,$debug = false,$commandOpt = []):在浏览器中打开 url,返回 QueryList
安装选项
QueryList::use(PhantomJs::class,$opt1,$opt2)
- $opt1:PhantomJS 二进制文件路径
- $opt2:
browser
函数别名。
用法
- 安装插件
use QL\QueryList; use QL\Ext\PhantomJs; $ql = QueryList::getInstance(); // Set PhantomJS bin path $ql->use(PhantomJs::class,'/usr/local/bin/phantomjs'); //or Custom function name $ql->use(PhantomJs::class,'/usr/local/bin/phantomjs','browser');
- 示例-1
$html = $ql->browser('https://m.toutiao.com')->getHtml(); print_r($html); $data = $ql->browser('https://m.toutiao.com')->find('p')->texts(); print_r($data->all()); // Command option see: http://phantomjs.org/api/command-line.html $ql->browser('https://m.toutiao.com',true,[ '--proxy' => '192.168.1.42:8080', '--proxy-type' => 'http' ])
- 示例-2
$data = $ql->browser(function (\JonnyW\PhantomJs\Http\RequestInterface $r){ $r->setMethod('GET'); $r->setUrl('https://m.toutiao.com'); $r->setTimeout(10000); // 10 seconds $r->setDelay(3); // 3 seconds return $r; })->find('p')->texts(); print_r($data->all());
- 示例-3
$data = $ql->browser(function (\JonnyW\PhantomJs\Http\RequestInterface $r){
$r->setMethod('GET');
$r->setUrl('https://m.toutiao.com');
$r->setTimeout(10000); // 10 seconds
$r->setDelay(3); // 3 seconds
return $r;
},true,[
'--cookies-file' => '/path/to/cookies.txt'
])->rules([
'title' => ['p','text'],
'link' => ['a','href']
])->query()->getData();
print_r($data->all());