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