瀏覽代碼

[fix] no more redirect ++ explicitly specify search language to avoid googles ip based heuristics

Adam Tauber 9 年之前
父節點
當前提交
6d55642ab4
共有 1 個檔案被更改,包括 5 行新增2 行删除
  1. 5
    2
      searx/engines/google.py

+ 5
- 2
searx/engines/google.py 查看文件

90
 search_path = '/search'
90
 search_path = '/search'
91
 search_url = ('https://{hostname}' +
91
 search_url = ('https://{hostname}' +
92
               search_path +
92
               search_path +
93
-              '?{query}&start={offset}&gbv=1&gws_rd=ssl')
93
+              '?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&ei=x')
94
 
94
 
95
 # other URLs
95
 # other URLs
96
 map_hostname_start = 'maps.google.'
96
 map_hostname_start = 'maps.google.'
160
     if params['language'] == 'all':
160
     if params['language'] == 'all':
161
         language = 'en'
161
         language = 'en'
162
         country = 'US'
162
         country = 'US'
163
+        url_lang = ''
163
     else:
164
     else:
164
         language_array = params['language'].lower().split('_')
165
         language_array = params['language'].lower().split('_')
165
         if len(language_array) == 2:
166
         if len(language_array) == 2:
167
         else:
168
         else:
168
             country = 'US'
169
             country = 'US'
169
         language = language_array[0] + ',' + language_array[0] + '-' + country
170
         language = language_array[0] + ',' + language_array[0] + '-' + country
171
+        url_lang = 'lang_' + language_array[0]
170
 
172
 
171
     if use_locale_domain:
173
     if use_locale_domain:
172
         google_hostname = country_to_hostname.get(country.upper(), default_hostname)
174
         google_hostname = country_to_hostname.get(country.upper(), default_hostname)
175
 
177
 
176
     params['url'] = search_url.format(offset=offset,
178
     params['url'] = search_url.format(offset=offset,
177
                                       query=urlencode({'q': query}),
179
                                       query=urlencode({'q': query}),
178
-                                      hostname=google_hostname)
180
+                                      hostname=google_hostname,
181
+                                      lang=url_lang)
179
 
182
 
180
     params['headers']['Accept-Language'] = language
183
     params['headers']['Accept-Language'] = language
181
     params['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
184
     params['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'