下面来演示QueryList运用Baidu搜刮引擎插件轻松完成站内搜刮。
装置
运用Composer装置:
装置QueryList
composer require jaeger/querylist
GitHub: https://github.com/jae-jae/Qu...
装置Baidu搜刮引擎插件
composer require jaeger/querylist-rule-baidu
GitHub: https://github.com/jae-jae/Qu...
插件API
● Baidu baidu($pageNumber = 10):猎取百度搜刮引擎
class Baidu:
● Baidu search($keyword):设置搜刮关键词
● Baidu setHttpOpt(array $httpOpt = []):设置HTTP选项,检察: GuzzleHttp options
● int getCount():猎取搜刮效果总条数
● int getCountPage():猎取搜刮效果总页数
● Collection page($page = 1,$realURL = false):猎取搜刮效果
运用
完成一个百度网盘资本搜刮引擎:
<?php require 'vendor/autoload.php'; use QL\QueryList; use QL\Ext\Baidu; $ql = QueryList::use(Baidu::class); // 搜刮百度网盘网站,包括‘百度’关键词的资本 $searcher = $ql->baidu()->search('site:pan.baidu.com 百度'); // 猎取第一页数据,并猎取实在URL衔接地点 $data = $searcher->page(1,true); print_r($data->all());
抓取效果:
Array ( [0] => Array ( [title] => 百度网盘_享你所想 [link] => http://pan.baidu.com/ ) [1] => Array ( [title] => 百度网盘 客户端下载 [link] => https://pan.baidu.com/download ) [2] => Array ( [title] => 百度网盘-开放平台 [link] => https://pan.baidu.com/platform/read ) // .... )
更多用法
$baidu = $ql->baidu(15); // 设置每页搜刮15条效果 $searcher = $baidu->search('QueryList'); $count = $searcher->getCount(); // 猎取搜刮效果总条数 $data = $searcher->page(1); $data = $searcher->page(2); $searcher = $baidu->search('php'); $countPage = $searcher->getCountPage(); // 猎取搜刮效果总页数 for ($page = 1; $page <= $countPage; $page++) { $data = $searcher->page($page); } $data = $searcher->setHttpOpt([ // 设置http代办 'proxy' => 'http://222.141.11.17:8118', // Set the timeout time in seconds 'timeout' => 30, ])->page(1);
Google搜刮引擎插件
固然除了Baidu搜刮引擎插件,QueryList也有Google搜刮引擎插件,也能够完成一样的功用。
GitHub: https://github.com/jae-jae/Qu...
更多PHP相干学问,请接见ki4网!
以上就是PHP运用QueryList轻松完成一个百度网盘资本搜刮引擎的细致内容,更多请关注ki4网别的相干文章!