Home>Article>Backend Development> PHP uses QueryList to easily implement a Baidu network disk resource search engine
QueryList uses jQuery for collection and has a wealth of plug-ins.
Let’s demonstrate how QueryList uses the Baidu search engine plug-in to easily implement on-site search.
Installation
Install using Composer:
Install QueryList
composer require jaeger/querylist
GitHub:https://github.com/jae-jae/Qu...
Install Baidu search engine plug-in
composer require jaeger/querylist-rule-baidu
GitHub:https://github.com/jae-jae/Qu...
Plug-in API
● Baidu baidu($pageNumber = 10): Get the Baidu search engine
class Baidu:
● Baidu search($keyword): Set the search keyword
● Baidu setHttpOpt(array $httpOpt = []): Set HTTP options, view:GuzzleHttp options
● int getCount(): Get the total number of search results
● int getCountPage() :Get the total number of search results pages
● Collection page($page = 1,$realURL = false):Get the search results
Use
Implement a Baidu network disk resource search engine:
baidu()->search('site:pan.baidu.com 百度'); // 获取第一页数据,并获取真实URL连接地址 $data = $searcher->page(1,true); print_r($data->all());
Fetch results:
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 ) // .... )
More usage
$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 Search Engine Plug-in
Of course, in addition to the Baidu search engine plug-in, QueryList also has a Google search engine plug-in, which can also achieve the same function.
GitHub:https://github.com/jae-jae/Qu...
For more PHP related knowledge, please visitPHP Chinese website!
The above is the detailed content of PHP uses QueryList to easily implement a Baidu network disk resource search engine. For more information, please follow other related articles on the PHP Chinese website!