QueryList使用jQuery的方式來做采集,擁有豐富的插件。
下面來演示QueryList使用Baidu搜索引擎插件輕松實現(xiàn)站內(nèi)搜索。
安裝
使用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):設(shè)置搜索關(guān)鍵詞
● Baidu setHttpOpt(array $httpOpt = []):設(shè)置HTTP選項,查看: GuzzleHttp options
● int getCount():獲取搜索結(jié)果總條數(shù)
● int getCountPage():獲取搜索結(jié)果總頁數(shù)
● Collection page($page = 1,$realURL = false):獲取搜索結(jié)果
使用
實現(xiàn)一個百度網(wǎng)盤資源搜索引擎:
<?php require 'vendor/autoload.php'; use QLQueryList; use QLExtBaidu; $ql = QueryList::use(Baidu::class); // 搜索百度網(wǎng)盤網(wǎng)站,包含‘百度’關(guān)鍵詞的資源 $searcher = $ql->baidu()->search('site:pan.baidu.com 百度'); // 獲取第一頁數(shù)據(jù),并獲取真實URL連接地址 $data = $searcher->page(1,true); print_r($data->all());
抓取結(jié)果:
Array ( [0] => Array ( [title] => 百度網(wǎng)盤_享你所想 [link] => http://pan.baidu.com/ ) [1] => Array ( [title] => 百度網(wǎng)盤 客戶端下載 [link] => https://pan.baidu.com/download ) [2] => Array ( [title] => 百度網(wǎng)盤-開放平臺 [link] => https://pan.baidu.com/platform/read ) // .... )