Browse Source

[fix] fetch_traits of google and zlibrary

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Markus Heiser 1 year ago
parent
commit
6df922b9da
2 changed files with 6 additions and 5 deletions
  1. 4 5
      searx/engines/google.py
  2. 2 0
      searx/engines/zlibrary.py

+ 4 - 5
searx/engines/google.py

@@ -430,14 +430,13 @@ def fetch_traits(engine_traits: EngineTraits, add_domains: bool = True):
     if not resp.ok:  # type: ignore
     if not resp.ok:  # type: ignore
         raise RuntimeError("Response from Google's preferences is not OK.")
         raise RuntimeError("Response from Google's preferences is not OK.")
 
 
-    dom = html.fromstring(resp.text)  # type: ignore
+    dom = html.fromstring(resp.text.replace('<?xml version="1.0" encoding="UTF-8"?>', ''))
 
 
     # supported language codes
     # supported language codes
 
 
     lang_map = {'no': 'nb'}
     lang_map = {'no': 'nb'}
-    for x in eval_xpath_list(dom, '//*[@id="langSec"]//input[@name="lr"]'):
-
-        eng_lang = x.get("value").split('_')[-1]
+    for x in eval_xpath_list(dom, "//select[@name='hl']/option"):
+        eng_lang = x.get("value")
         try:
         try:
             locale = babel.Locale.parse(lang_map.get(eng_lang, eng_lang), sep='-')
             locale = babel.Locale.parse(lang_map.get(eng_lang, eng_lang), sep='-')
         except babel.UnknownLocaleError:
         except babel.UnknownLocaleError:
@@ -457,7 +456,7 @@ def fetch_traits(engine_traits: EngineTraits, add_domains: bool = True):
 
 
     # supported region codes
     # supported region codes
 
 
-    for x in eval_xpath_list(dom, '//*[@name="region"]/..//input[@name="region"]'):
+    for x in eval_xpath_list(dom, "//select[@name='gl']/option"):
         eng_country = x.get("value")
         eng_country = x.get("value")
 
 
         if eng_country in skip_countries:
         if eng_country in skip_countries:

+ 2 - 0
searx/engines/zlibrary.py

@@ -200,6 +200,8 @@ def fetch_traits(engine_traits: EngineTraits) -> None:
     for locale in babel.core.localedata.locale_identifiers():  # type: ignore
     for locale in babel.core.localedata.locale_identifiers():  # type: ignore
         # Create a Locale object for the current locale
         # Create a Locale object for the current locale
         loc = babel.Locale.parse(locale)
         loc = babel.Locale.parse(locale)
+        if loc.english_name is None:
+            continue
         language_name_locale_map[loc.english_name.lower()] = loc  # type: ignore
         language_name_locale_map[loc.english_name.lower()] = loc  # type: ignore
 
 
     for x in eval_xpath_list(dom, "//div[@id='advSearch-noJS']//select[@id='sf_languages']/option"):
     for x in eval_xpath_list(dom, "//div[@id='advSearch-noJS']//select[@id='sf_languages']/option"):