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

This commit is contained in:
Adam Tauber 2016-03-25 18:38:02 +01:00
parent ba16f213b0
commit 6d55642ab4

View file

@ -90,7 +90,7 @@ url_map = 'https://www.openstreetmap.org/'\
search_path = '/search' search_path = '/search'
search_url = ('https://{hostname}' + search_url = ('https://{hostname}' +
search_path + search_path +
'?{query}&start={offset}&gbv=1&gws_rd=ssl') '?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&ei=x')
# other URLs # other URLs
map_hostname_start = 'maps.google.' map_hostname_start = 'maps.google.'
@ -160,6 +160,7 @@ def request(query, params):
if params['language'] == 'all': if params['language'] == 'all':
language = 'en' language = 'en'
country = 'US' country = 'US'
url_lang = ''
else: else:
language_array = params['language'].lower().split('_') language_array = params['language'].lower().split('_')
if len(language_array) == 2: if len(language_array) == 2:
@ -167,6 +168,7 @@ def request(query, params):
else: else:
country = 'US' country = 'US'
language = language_array[0] + ',' + language_array[0] + '-' + country language = language_array[0] + ',' + language_array[0] + '-' + country
url_lang = 'lang_' + language_array[0]
if use_locale_domain: if use_locale_domain:
google_hostname = country_to_hostname.get(country.upper(), default_hostname) google_hostname = country_to_hostname.get(country.upper(), default_hostname)
@ -175,7 +177,8 @@ def request(query, params):
params['url'] = search_url.format(offset=offset, params['url'] = search_url.format(offset=offset,
query=urlencode({'q': query}), query=urlencode({'q': query}),
hostname=google_hostname) hostname=google_hostname,
lang=url_lang)
params['headers']['Accept-Language'] = language params['headers']['Accept-Language'] = language
params['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' params['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'