From 68a08325241478df8374a8dd640d74648bdc4b72 Mon Sep 17 00:00:00 2001 From: asciimoo Date: Fri, 31 Jan 2014 05:10:49 +0100 Subject: [PATCH] [enh] search language support upadtes --- searx/engines/startpage.py | 9 +++++++-- searx/engines/yahoo.py | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/searx/engines/startpage.py b/searx/engines/startpage.py index ab331a0ba..fcfc21160 100644 --- a/searx/engines/startpage.py +++ b/searx/engines/startpage.py @@ -6,20 +6,25 @@ search_url = None # TODO paging paging = False +# TODO complete list of country mapping +country_map = {'en_US': 'eng', + 'en_UK': 'uk', + 'nl_NL': 'ned'} def request(query, params): - global search_url query = urlencode({'q': query})[2:] params['url'] = search_url params['method'] = 'POST' params['data'] = {'query': query, 'startat': (params['pageno'] - 1) * 10} # offset + country = country_map.get(params['language'], 'eng') + params['cookies']['preferences'] = \ + 'lang_homepageEEEs/air/{country}/N1NsslEEE1N1Nfont_sizeEEEmediumN1Nrecent_results_filterEEE1N1Nlanguage_uiEEEenglishN1Ndisable_open_in_new_windowEEE0N1Ncolor_schemeEEEnewN1Nnum_of_resultsEEE10N1N'.format(country=country) # noqa return params def response(resp): - global base_url results = [] dom = html.fromstring(resp.content) # ads xpath //div[@id="results"]/div[@id="sponsored"]//div[@class="result"] diff --git a/searx/engines/yahoo.py b/searx/engines/yahoo.py index ab69bd6a9..2fbd785cf 100644 --- a/searx/engines/yahoo.py +++ b/searx/engines/yahoo.py @@ -17,8 +17,14 @@ paging = True def request(query, params): offset = (params['pageno'] - 1) * 10 + 1 + if params['language'] == 'all': + language = 'en' + else: + language = params['language'].split('_')[0] params['url'] = search_url.format(offset=offset, query=urlencode({'p': query})) + params['cookies']['sB'] = 'fl=1&vl=lang_{lang}&sh=1&rw=new&v=1'\ + .format(lang=language) return params