Browse Source

add http opt

Jaeger 9 năm trước cách đây
mục cha
commit
b79ede9342
2 tập tin đã thay đổi với 21 bổ sung1 xóa
  1. 8 1
      Baidu.php
  2. 13 0
      README.md

+ 8 - 1
Baidu.php

@@ -16,6 +16,7 @@ class Baidu implements PluginContract
     protected $ql;
     protected $keyword;
     protected $pageNumber = 10;
+    protected $httpOpt = [];
     const API = 'https://www.baidu.com/s';
     const RULES = [
       'title' => ['h3','text'],
@@ -37,6 +38,12 @@ class Baidu implements PluginContract
         });
     }
 
+    public function setHttpOpt(array $httpOpt = [])
+    {
+        $this->httpOpt = $httpOpt;
+        return $this;
+    }
+
     public function search($keyword)
     {
         $this->keyword = $keyword;
@@ -75,7 +82,7 @@ class Baidu implements PluginContract
             'wd' => $this->keyword,
             'rn' => $this->pageNumber,
             'pn' => $this->pageNumber * ($page-1)
-        ]);
+        ],$this->httpOpt);
         return $this->ql;
     }
 

+ 13 - 0
README.md

@@ -13,6 +13,7 @@ composer require jaeger/querylist-rule-baidu
 
 class **Baidu**:
 - Baidu **search($keyword)**:set search keyword.
+- Baidu **setHttpOpt(array $httpOpt = [])**:Set the http option,see: [GuzzleHttp options](http://docs.guzzlephp.org/en/stable/request-options.html)
 - int **getCount()**:Get the total number of search results.
 - int **getCountPage()**:Get the total number of pages.
 - Collection **page($page = 1,$realURL = false)**:Get search results
@@ -48,6 +49,18 @@ for ($page = 1; $page <= $countPage; $page++)
 
 - Example-2
 
+```
+$searcher = $ql->baidu()->search('QueryList');
+$data = $searcher->setHttpOpt([
+    // Set the http proxy
+    'proxy' => 'http://222.141.11.17:8118',
+   // Set the timeout time in seconds
+    'timeout' => 30,
+])->page(1);
+```
+
+- Example-3
+
 ```
 $baidu = $ql->baidu(3)
 $searcher = $baidu->search('QueryList');