diff options
author | marc <a01200356@itesm.mx> | 2016-12-15 00:34:43 -0600 |
---|---|---|
committer | marc <a01200356@itesm.mx> | 2016-12-15 00:40:21 -0600 |
commit | af35eee10b98940c51c6e5e18629de514b4bd48d (patch) | |
tree | 804b0a4cfe08bb897541e9e8571b921a78e07992 /searx/engines/google.py | |
parent | e0c270bd72f7b2a40222e3ed264e25d36cb0fc30 (diff) | |
download | searxng-af35eee10b98940c51c6e5e18629de514b4bd48d.tar.gz searxng-af35eee10b98940c51c6e5e18629de514b4bd48d.zip |
tests for _fetch_supported_languages in engines
and refactor method to make it testable without making requests
Diffstat (limited to 'searx/engines/google.py')
-rw-r--r-- | searx/engines/google.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/searx/engines/google.py b/searx/engines/google.py index a82a0b5a7..803cd307e 100644 --- a/searx/engines/google.py +++ b/searx/engines/google.py @@ -12,7 +12,6 @@ import re from urllib import urlencode from urlparse import urlparse, parse_qsl from lxml import html, etree -from requests import get from searx.engines.xpath import extract_text, extract_url from searx.search import logger @@ -364,14 +363,13 @@ def attributes_to_html(attributes): # get supported languages from their site -def fetch_supported_languages(): +def _fetch_supported_languages(resp): supported_languages = {} - response = get(supported_languages_url) - dom = html.fromstring(response.text) - options = dom.xpath('//select[@name="hl"]/option') + dom = html.fromstring(resp.text) + options = dom.xpath('//table//td/font/label/span') for option in options: - code = option.xpath('./@value')[0].split('-')[0] - name = option.text[:-1].title() + code = option.xpath('./@id')[0][1:] + name = option.text.title() supported_languages[code] = {"name": name} return supported_languages |