yqcode/querylist-ext-phantomjs

QueryList V3 Plugin: Use PhantomJS to crawl Javascript dynamically rendered pages.(headless WebKit )

v1.0 2019-08-22 07:44 UTC

This package is not auto-updated.

Last update: 2024-04-27 04:53:36 UTC


README

QueryList V3 Plugin: Use PhantomJS to crawl Javascript dynamically rendered pages.(headless WebKit )

querylist-ext-phantomjs 安装

通过composer安装:

composer require huanyq2008/querylist-ext-phantomjs

querylist-ext-phantomjs 使用

下面演示QueryList用一句代码采集页面信息:

$urlarr = [
    'https://mimvp.com',  // 默认 utf-8
    'https://www.qq.com', // 默认 gb2312,需添加 header,否则乱码
    'https://www.dajie.com', // content在前,name在后,匹配错误(从第一个content开始,从最后一个name结束)
    'https://m.toutiao.com',
    'https://www.baidu.com',
    'https://mp.weixin.qq.com/s/NHD6BXCbJYzl4gK-NYBKaw',
];
//插件调用
$ql = QueryList::run('PhantomJs', [
    'binpath'=>'/usr/bin/phantomjs', 
    'url'=>$urlarr[0],
    'debug'=>false
]);
//设置规则
$data = $ql->setQuery(array(
    'title' => array('title','text'),
    'keywords' => array('meta[name=keywords]','content'),
    'description' => array('meta[name=description]','content'),
    'img' => array('img','src')
))->data;
print_r($data);

上面的代码实现的功能是采集相关页面的标题关键字描述图片,然后分别以二维关联数组的格式输出。