1
1
<?php
2
2
class GoogleRequest extends EngineRequest {
3
+ protected string $ arc_id ;
4
+ protected int $ arc_timestamp = 0 ;
5
+
6
+ private function generate_arc_id () {
7
+ $ charset = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_- " ;
8
+ $ this ->arc_id = "srp_ " ;
9
+
10
+ for ($ i = 0 ; $ i < 24 ; $ i ++) {
11
+ $ c = random_int (0 , strlen ($ charset ) - 1 );
12
+ $ this ->arc_id .= $ charset [$ c ];
13
+ }
14
+
15
+ $ this ->arc_id .= "_1 " ;
16
+ $ this ->arc_timestamp = time ();
17
+ }
18
+
3
19
public function get_request_url () {
20
+ if ($ this ->arc_timestamp + 3600 < time ())
21
+ $ this ->generate_arc_id ();
4
22
5
23
$ query_encoded = str_replace ("%22 " , "\"" , urlencode ($ this ->query ));
6
24
$ results = array ();
7
25
8
26
$ domain = $ this ->opts ->google_domain ;
9
27
$ results_language = $ this ->opts ->language ;
10
28
$ number_of_results = $ this ->opts ->number_of_results ;
29
+ $ arc_page = sprintf ("%02d " , $ this ->page * 10 );
11
30
12
31
$ url = "https://www.google. $ domain/search?q= $ query_encoded&nfpr=1&start= $ this ->page " ;
13
32
@@ -22,6 +41,8 @@ public function get_request_url() {
22
41
if (isset ($ _COOKIE ["safe_search " ]))
23
42
$ url .= "&safe=medium " ;
24
43
44
+ $ url .= "&asearch=arc&async=arc_id: $ this ->arc_id $ arc_page,use_ac:true,_fmt:html " ;
45
+
25
46
return $ url ;
26
47
}
27
48
@@ -33,21 +54,21 @@ public function parse_results($response) {
33
54
if (!$ xpath )
34
55
return $ results ;
35
56
36
- $ didyoumean = $ xpath ->query (".//a [@class='gL9Hy'] " )[0 ];
57
+ $ didyoumean = $ xpath ->query (".//p [@class='QRYxYe NNMgCf']/a/b/i " )[0 ];
37
58
38
59
if (!is_null ($ didyoumean ))
39
60
array_push ($ results , array (
40
61
"did_you_mean " => $ didyoumean ->textContent
41
62
));
42
63
43
- foreach ($ xpath ->query ("//div[@id='search']//div[contains(@class, 'g') ] " ) as $ result ) {
44
- $ url = $ xpath ->evaluate (".//div [@class='yuRUbf']//a /@href " , $ result )[0 ];
64
+ foreach ($ xpath ->query ("//div[@class='MjjYud' ] " ) as $ result ) {
65
+ $ url = $ xpath ->evaluate (".//a [@class='zReHs'] /@href " , $ result )[0 ];
45
66
46
67
if ($ url == null )
47
68
continue ;
48
69
49
70
if (!empty ($ results ) && array_key_exists ("url " , end ($ results )) && end ($ results )["url " ] == $ url ->textContent )
50
- continue ;
71
+ continue ;
51
72
52
73
$ url = $ url ->textContent ;
53
74
0 commit comments