|
@@ -11,6 +11,7 @@
|
11
|
11
|
from urllib import urlencode
|
12
|
12
|
from urlparse import urlparse, parse_qsl
|
13
|
13
|
from lxml import html
|
|
14
|
+from searx.poolrequests import get
|
14
|
15
|
from searx.engines.xpath import extract_text, extract_url
|
15
|
16
|
|
16
|
17
|
# engine dependent config
|
|
@@ -39,6 +40,17 @@ images_xpath = './/div/a'
|
39
|
40
|
image_url_xpath = './@href'
|
40
|
41
|
image_img_src_xpath = './img/@src'
|
41
|
42
|
|
|
43
|
+pref_cookie = ''
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+# see https://support.google.com/websearch/answer/873?hl=en
|
|
47
|
+def get_google_pref_cookie():
|
|
48
|
+ global pref_cookie
|
|
49
|
+ if pref_cookie == '':
|
|
50
|
+ resp = get('https://www.google.com/ncr', allow_redirects=False)
|
|
51
|
+ pref_cookie = resp.cookies["PREF"]
|
|
52
|
+ return pref_cookie
|
|
53
|
+
|
42
|
54
|
|
43
|
55
|
# remove google-specific tracking-url
|
44
|
56
|
def parse_url(url_string):
|
|
@@ -64,6 +76,7 @@ def request(query, params):
|
64
|
76
|
query=urlencode({'q': query}))
|
65
|
77
|
|
66
|
78
|
params['headers']['Accept-Language'] = language
|
|
79
|
+ params['cookies']['PREF'] = get_google_pref_cookie()
|
67
|
80
|
|
68
|
81
|
return params
|
69
|
82
|
|