首頁  >  文章  >  後端開發  >  PHP使用QueryList輕鬆實作一個百度網盤資源搜尋引擎

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

藏色散人
藏色散人轉載
2019-10-16 14:13:134607瀏覽

QueryList使用jQuery的方式來做採集,擁有豐富的外掛。

下面來示範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):取得搜尋結果

使用

#實作一個百度網盤資源搜尋引擎:

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相關知識,請造訪###PHP中文網###! ###

以上是PHP使用QueryList輕鬆實作一個百度網盤資源搜尋引擎的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:segmentfault.com。如有侵權,請聯絡admin@php.cn刪除