Google 插件



  • 谷歌搜索引擎,采集谷歌的搜索结果。国内使用这个插件需要使用代理。
GitHub: https://github.com/jae-jae/QueryList-Rule-Google

安装

  1. composer require jaeger/querylist-rule-google

API

  • Google google($pageNumber = 10):获取谷歌搜索引擎
    class Google:

  • Google search($keyword):设置搜索关键词

  • Google setHttpOpt(array $httpOpt = []):设置HTTP选项,查看: GuzzleHttp options
  • int getCount():获取搜索结果总条数
  • int getCountPage():获取搜索结果总页数
  • Collection page($page = 1):获取搜索结果

Usage

  • Installation Plugin
  1. use QL\QueryList;
  2. use QL\Ext\Google;
  3. $ql = QueryList::getInstance();
  4. $ql->use(Google::class);
  5. //or Custom function name
  6. $ql->use(Google::class,'google');
  • Example-1
  1. $google = $ql->google(10)
  2. $searcher = $google->search('QueryList');
  3. $count = $searcher->getCount();
  4. $data = $searcher->page(1);
  5. $data = $searcher->page(2);
  6. $searcher = $google->search('php');
  7. $countPage = $searcher->getCountPage();
  8. for ($page = 1; $page <= $countPage; $page++)
  9. {
  10. $data = $searcher->page($page);
  11. }
  • Example-2
  1. $searcher = $ql->google()->search('QueryList');
  2. $data = $searcher->setHttpOpt([
  3. // Set the http proxy
  4. 'proxy' => 'http://222.141.11.17:8118',
  5. // Set the timeout time in seconds
  6. 'timeout' => 30,
  7. ])->page(1);
  8. print_r($data->all());
  • Example-3
  1. $data= $searcher = $ql->google(3)->search('QueryList')->page(1);
  2. print_r($data->all());

Out:

  1. Array
  2. (
  3. [0] => Array
  4. (
  5. [title] => Angular - QueryList
  6. [link] => https://angular.io/api/core/QueryList
  7. )
  8. [1] => Array
  9. (
  10. [title] => QueryList | @angular/core - Angularリファレンス - Web Creative Park
  11. [link] => http://www.webcreativepark.net/angular/querylist/
  12. )
  13. [2] => Array
  14. (
  15. [title] => Understanding ViewChildren, ContentChildren, and QueryList in ...
  16. [link] => https://netbasal.com/understanding-viewchildren-contentchildren-and-querylist-in-angular-896b0c689f6e
  17. )
  18. )