diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2020-03-01 08:01:36 +0100 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2020-03-01 08:01:36 +0100 |
commit | e0c99d9dcbe4c2eee0a7c6f4a7326a8376467640 (patch) | |
tree | fb5397b6e1c12469533b0cf40d0ab3e657b7e7a8 /searx/engines/bing.py | |
parent | 40843fe95ada52bc8791b4706392bda5afecf32e (diff) | |
download | searxng-e0c99d9dcbe4c2eee0a7c6f4a7326a8376467640.tar.gz searxng-e0c99d9dcbe4c2eee0a7c6f4a7326a8376467640.zip |
bugfix: fetch_supported_languages bing, -news, -videos, -images
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/bing.py')
-rw-r--r-- | searx/engines/bing.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/searx/engines/bing.py b/searx/engines/bing.py index b193f7c60..c8fc4fa2e 100644 --- a/searx/engines/bing.py +++ b/searx/engines/bing.py @@ -110,13 +110,18 @@ def response(resp): # get supported languages from their site def _fetch_supported_languages(resp): - supported_languages = [] + lang_tags = set() + + setmkt = re.compile('setmkt=([^&]*)') dom = html.fromstring(resp.text) - options = eval_xpath(dom, '//div[@id="limit-languages"]//input') - for option in options: - code = eval_xpath(option, './@id')[0].replace('_', '-') - if code == 'nb': - code = 'no' - supported_languages.append(code) - - return supported_languages + lang_links = eval_xpath(dom, "//li/a[contains(@href, 'setmkt')]") + + for a in lang_links: + href = eval_xpath(a, './@href')[0] + match = setmkt.search(href) + l_tag = match.groups()[0] + _lang, _nation = l_tag.split('-',1) + l_tag = _lang.lower() + '-' + _nation.upper() + lang_tags.add(l_tag) + + return list(lang_tags) |