logo

searx

Unnamed repository; edit this file 'description' to name the repository.
commit: 68a08325241478df8374a8dd640d74648bdc4b72
parent: 2a788c8f29f63bc069436f1a12343a47d66f2523
Author: asciimoo <asciimoo@gmail.com>
Date:   Fri, 31 Jan 2014 05:10:49 +0100

[enh] search language support upadtes

Diffstat:

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 @@ -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 @@ -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