Home > Backend Development > PHP Tutorial > PHP uses QueryList to easily implement a Baidu network disk resource search engine

PHP uses QueryList to easily implement a Baidu network disk resource search engine

藏色散人
Release: 2023-04-07 17:24:01
forward
4870 people have browsed it

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:

<?php
require &#39;vendor/autoload.php&#39;;
use QL\QueryList;
use QL\Ext\Baidu;
$ql = QueryList::use(Baidu::class);
// 搜索百度网盘网站,包含‘百度’关键词的资源
$searcher = $ql->baidu()->search(&#39;site:pan.baidu.com 百度&#39;);
// 获取第一页数据,并获取真实URL连接地址
$data = $searcher->page(1,true);
print_r($data->all());
Copy after login

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
        )
     // ....
)
Copy after login

More usage

$baidu = $ql->baidu(15); // 设置每页搜索15条结果
$searcher = $baidu->search(&#39;QueryList&#39;);
$count = $searcher->getCount();  // 获取搜索结果总条数
$data = $searcher->page(1);
$data = $searcher->page(2);
$searcher = $baidu->search(&#39;php&#39;);
$countPage = $searcher->getCountPage(); // 获取搜索结果总页数
for ($page = 1; $page <= $countPage; $page++)
{
    $data = $searcher->page($page);
}
$data = $searcher->setHttpOpt([
    // 设置http代理
    &#39;proxy&#39; => &#39;http://222.141.11.17:8118&#39;,
   // Set the timeout time in seconds
    &#39;timeout&#39; => 30,
])->page(1);
Copy after login

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 visit PHP 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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template