|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace rOpenDev\Google; |
|
4
|
|
|
|
|
5
|
|
|
use rOpenDev\curl\CurlRequest; |
|
6
|
|
|
|
|
7
|
|
|
class SearchViaCurl extends Search |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
protected $referrer; |
|
11
|
|
|
protected $cookie; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @return string|false Contenu html de la page |
|
15
|
|
|
*/ |
|
16
|
|
|
protected function requestGoogle($url) |
|
17
|
|
|
{ |
|
18
|
|
|
$cache = $this->getCache($url); |
|
19
|
|
|
if (false !== $cache) { |
|
20
|
|
|
return $cache; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
$curl = new CurlRequest($url); |
|
24
|
|
|
$curl->setDefaultGetOptions()->setReturnHeader()->setEncodingGzip(); |
|
25
|
|
|
|
|
26
|
|
|
if (isset($this->language)) { |
|
27
|
|
|
$curl->setOpt(CURLOPT_HTTPHEADER, ['Accept-Language: '.$this->language]); |
|
28
|
|
|
} |
|
29
|
|
|
if (isset($this->userAgent)) { |
|
30
|
|
|
$curl->setUserAgent($this->userAgent); |
|
31
|
|
|
} else { |
|
32
|
|
|
if ($this->mobile) { |
|
33
|
|
|
$curl->setDestkopUserAgent(); |
|
34
|
|
|
} else { |
|
35
|
|
|
$curl->setMobileUserAgent(); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
if (isset($this->proxy)) { |
|
40
|
|
|
$curl->setProxy($this->proxy); |
|
41
|
|
|
} |
|
42
|
|
|
if (isset($this->referrer)) { |
|
43
|
|
|
$curl->setReferrer($this->referrer); |
|
44
|
|
|
} |
|
45
|
|
|
if (isset($this->cookie)) { |
|
46
|
|
|
$curl->setCookie($this->cookie); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$output = $curl->execute(); |
|
50
|
|
|
|
|
51
|
|
|
/* Erreur logs de l'éxecution du cURL **/ |
|
52
|
|
|
if ($curl->hasError()) { |
|
53
|
|
|
$this->cErrors = $curl->getErrors(); |
|
54
|
|
|
$this->error = 1; |
|
55
|
|
|
|
|
56
|
|
|
return false; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$amIKicked = $this->amIKickedByGoogleThePowerful($output); |
|
60
|
|
|
if (false !== $amIKicked) { |
|
61
|
|
|
$this->error = $amIKicked; |
|
62
|
|
|
|
|
63
|
|
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/* Tout est Ok, on enregistre et on renvoit le html **/ |
|
67
|
|
|
$this->setCache($url, $output); |
|
68
|
|
|
|
|
69
|
|
|
$this->cookie = $curl->getCookies(); |
|
70
|
|
|
$this->referrer = $curl->getEffectiveUrl(); |
|
71
|
|
|
$this->execSleep(); |
|
72
|
|
|
|
|
73
|
|
|
return $output; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|