[refactor] duckduckgo: use extr helper function in get_vqd

This commit is contained in:
Bnyro 2024-06-14 14:39:22 +02:00 committed by Markus Heiser
parent 7be468d213
commit 1fe13d0ba4

View file

@ -24,6 +24,7 @@ from searx.utils import (
from searx.network import get # see https://github.com/searxng/searxng/issues/762 from searx.network import get # see https://github.com/searxng/searxng/issues/762
from searx import redisdb from searx import redisdb
from searx.enginelib.traits import EngineTraits from searx.enginelib.traits import EngineTraits
from searx.utils import extr
if TYPE_CHECKING: if TYPE_CHECKING:
import logging import logging
@ -120,8 +121,7 @@ def get_vqd(query):
for script in doc.xpath("//script[@type='text/javascript']"): for script in doc.xpath("//script[@type='text/javascript']"):
script = script.text script = script.text
if 'vqd="' in script: if 'vqd="' in script:
value = script[script.index('vqd="') + 5 :] value = extr(script, 'vqd="', '"')
value = value[: value.index('"')]
break break
logger.debug("new vqd value: '%s'", value) logger.debug("new vqd value: '%s'", value)
if value is not None: if value is not None:
@ -393,7 +393,7 @@ def fetch_traits(engine_traits: EngineTraits):
""" """
# pylint: disable=too-many-branches, too-many-statements, disable=import-outside-toplevel # pylint: disable=too-many-branches, too-many-statements, disable=import-outside-toplevel
from searx.utils import extr, js_variable_to_python from searx.utils import js_variable_to_python
# fetch regions # fetch regions