1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-22 12:10:11 +01:00

[mod] google: add "use_mobile_ui" parameter to use mobile endpoint.

disable by default, it has to be enabled in settings.yml

related to  #159
This commit is contained in:
Alexandre Flament 2021-06-21 12:18:28 +02:00
parent 0e3a87b73a
commit 7a5c36408a
2 changed files with 25 additions and 11 deletions

View File

@ -34,6 +34,7 @@ categories = ['general']
paging = True
time_range_support = True
safesearch = True
use_mobile_ui = False
supported_languages_url = 'https://www.google.com/preferences?#languages'
# based on https://en.wikipedia.org/wiki/List_of_Google_domains and tests
@ -266,6 +267,13 @@ def request(query, params):
params, supported_languages, language_aliases, True
)
additional_parameters = {}
if use_mobile_ui:
additional_parameters = {
'asearch': "arc",
'async': 'arc_id:srp_510,ffilt:all,ve_name:MoreResultsContainer,next_id:srp_5,use_ac:true,_id:arc-srp_510,_pms:qs,_fmt:pc' # pylint: disable=line-too-long
}
# https://www.google.de/search?q=corona&hl=de&lr=lang_de&start=0&tbs=qdr%3Ad&safe=medium
query_url = 'https://' + lang_info['subdomain'] + '/search' + "?" + urlencode({
'q': query,
@ -273,6 +281,7 @@ def request(query, params):
'ie': "utf8",
'oe': "utf8",
'start': offset,
**additional_parameters,
})
if params['time_range'] in time_range_dict:
@ -282,6 +291,9 @@ def request(query, params):
params['url'] = query_url
params['headers'].update(lang_info['headers'])
if use_mobile_ui:
params['headers']['Accept'] = '*/*'
else:
params['headers']['Accept'] = (
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
)
@ -307,6 +319,7 @@ def response(resp):
logger.debug("did not find 'answer'")
# results --> number_of_results
if not use_mobile_ui:
try:
_txt = eval_xpath_getindex(dom, '//div[@id="result-stats"]//text()', 0)
_digit = ''.join([n for n in _txt if n.isdigit()])

View File

@ -583,6 +583,7 @@ engines:
- name: google
engine: google
shortcut: go
use_mobile_ui: true
# additional_tests:
# android: *test_android