mirror of https://github.com/searx/searx
[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:
parent
3863f5a83f
commit
8bf216eab6
|
@ -33,6 +33,7 @@ categories = ['general']
|
||||||
paging = True
|
paging = True
|
||||||
time_range_support = True
|
time_range_support = True
|
||||||
safesearch = True
|
safesearch = True
|
||||||
|
use_mobile_ui = False
|
||||||
supported_languages_url = 'https://www.google.com/preferences?#languages'
|
supported_languages_url = 'https://www.google.com/preferences?#languages'
|
||||||
|
|
||||||
# based on https://en.wikipedia.org/wiki/List_of_Google_domains and tests
|
# based on https://en.wikipedia.org/wiki/List_of_Google_domains and tests
|
||||||
|
@ -206,6 +207,13 @@ def request(query, params):
|
||||||
params, supported_languages, language_aliases, True
|
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
|
# 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({
|
query_url = 'https://' + lang_info['subdomain'] + '/search' + "?" + urlencode({
|
||||||
'q': query,
|
'q': query,
|
||||||
|
@ -213,6 +221,7 @@ def request(query, params):
|
||||||
'ie': "utf8",
|
'ie': "utf8",
|
||||||
'oe': "utf8",
|
'oe': "utf8",
|
||||||
'start': offset,
|
'start': offset,
|
||||||
|
**additional_parameters,
|
||||||
})
|
})
|
||||||
|
|
||||||
if params['time_range'] in time_range_dict:
|
if params['time_range'] in time_range_dict:
|
||||||
|
@ -225,6 +234,9 @@ def request(query, params):
|
||||||
|
|
||||||
logger.debug("HTTP header Accept-Language --> %s", lang_info.get('Accept-Language'))
|
logger.debug("HTTP header Accept-Language --> %s", lang_info.get('Accept-Language'))
|
||||||
params['headers'].update(lang_info['headers'])
|
params['headers'].update(lang_info['headers'])
|
||||||
|
if use_mobile_ui:
|
||||||
|
params['headers']['Accept'] = '*/*'
|
||||||
|
else:
|
||||||
params['headers']['Accept'] = (
|
params['headers']['Accept'] = (
|
||||||
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
|
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
|
||||||
)
|
)
|
||||||
|
@ -250,6 +262,7 @@ def response(resp):
|
||||||
logger.debug("did not find 'answer'")
|
logger.debug("did not find 'answer'")
|
||||||
|
|
||||||
# results --> number_of_results
|
# results --> number_of_results
|
||||||
|
if not use_mobile_ui:
|
||||||
try:
|
try:
|
||||||
_txt = eval_xpath_getindex(dom, '//div[@id="result-stats"]//text()', 0)
|
_txt = eval_xpath_getindex(dom, '//div[@id="result-stats"]//text()', 0)
|
||||||
_digit = ''.join([n for n in _txt if n.isdigit()])
|
_digit = ''.join([n for n in _txt if n.isdigit()])
|
||||||
|
|
|
@ -551,6 +551,7 @@ engines:
|
||||||
- name : google
|
- name : google
|
||||||
engine : google
|
engine : google
|
||||||
shortcut : go
|
shortcut : go
|
||||||
|
use_mobile_ui: false
|
||||||
# additional_tests:
|
# additional_tests:
|
||||||
# android: *test_android
|
# android: *test_android
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue