Baidu 插件



  • 百度搜索引擎,采集百度搜索结果。
GitHub: https://github.com/jae-jae/QueryList-Rule-Baidu

安装

  1. composer require jaeger/querylist-rule-baidu

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):获取搜索结果

用法

  • Installation Plugin
  1. use QL\QueryList;
  2. use QL\Ext\Baidu;
  3. $ql = QueryList::getInstance();
  4. $ql->use(Baidu::class);
  5. //or Custom function name
  6. $ql->use(Baidu::class,'baidu');
  • Example-1
  1. $baidu = $ql->baidu(15); // 设置每页搜索15条结果
  2. $searcher = $baidu->search('QueryList');
  3. $count = $searcher->getCount(); // 获取搜索结果总条数
  4. $data = $searcher->page(1);
  5. $data = $searcher->page(2);
  6. $searcher = $baidu->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->baidu()->search('QueryList');
  2. $data = $searcher->setHttpOpt([
  3. // 设置http代理
  4. 'proxy' => 'http://222.141.11.17:8118',
  5. // Set the timeout time in seconds
  6. 'timeout' => 30,
  7. ])->page(1);
  • Example-3
  1. $baidu = $ql->baidu(3)
  2. $searcher = $baidu->search('QueryList');
  3. $data = $searcher->page(1);
  4. print_r($data->all());
  5. // Get real url
  6. $data = $searcher->page(1,true);
  7. print_r($data->all());

Out:

  1. Array
  2. (
  3. [0] => Array
  4. (
  5. [title] => QueryList|基于phpQuery的无比强大的PHP采集工具
  6. [link] => http://www.baidu.com/link?url=qRAXrUIcrxuLQ4Pn_rL25HvpDwugxgLkmwB74wTBuLflWaDTNY1d27gdxMwddbfn
  7. )
  8. [1] => Array
  9. (
  10. [title] => 介绍- QueryList指导文档
  11. [link] => http://www.baidu.com/link?url=NgoB517LCcb7tt37_x74uF0N-8pfhSemhA5qoB0SHf8HY9P_MwKbN80nf9zvd3V5
  12. )
  13. [2] => Array
  14. (
  15. [title] => PHP QueryList抓取网页内容 - wb145230 - 博客园
  16. [link] => http://www.baidu.com/link?url=kDkpY9eZ6CsiT1SWomRWEYPauHseHn2FseSdPnsOoulWCkD3DK6QMT75urFGHLyeG_M9yTD0BCm-s5jGQRi_S_
  17. )
  18. )
  19. Array
  20. (
  21. [0] => Array
  22. (
  23. [title] => QueryList|基于phpQuery的无比强大的PHP采集工具
  24. [link] => http://www.querylist.cc/
  25. )
  26. [1] => Array
  27. (
  28. [title] => 介绍- QueryList指导文档
  29. [link] => http://doc.querylist.cc/
  30. )
  31. [2] => Array
  32. (
  33. [title] => PHP QueryList抓取网页内容 - wb145230 - 博客园
  34. [link] => http://www.cnblogs.com/wb145230/p/4716403.html
  35. )
  36. )