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):獲取搜索結果
使用
實現一個百度網盤資源搜索引擎:
<?php require 'vendor/autoload.php'; use QLQueryList; use QLExtBaidu; $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 ) // .... )