PHP使用QueryList輕鬆實現一個百度網盤資源搜索引擎

QueryList使用jQuery的方式來作採集,擁有豐富的插件。php

下面來演示QueryList使用Baidu搜索引擎插件輕鬆實現站內搜索。html

安裝

使用Composer安裝:git

  • 安裝QueryList
composer require jaeger/querylist

GitHub: https://github.com/jae-jae/Qu...github

  • 安裝Baidu搜索引擎插件
composer require jaeger/querylist-rule-baidu

GitHub: https://github.com/jae-jae/Qu...composer

插件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());

抓取結果:ui

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搜索引擎插件,也能夠實現一樣的功能。搜索引擎

文檔: https://doc.querylist.cc/site...
GitHub: https://github.com/jae-jae/Qu...插件

相關文章
相關標籤/搜索