summaryrefslogtreecommitdiff
path: root/searx/engines/brave.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarIT.de>2025-11-25 12:51:08 +0100
committerGitHub <noreply@github.com>2025-11-25 12:51:08 +0100
commit54a97e10431c1cdae910d3b37074a63eda7100fc (patch)
tree3769dc3a7eae53ad96660cf47dfc476b8c26963d /searx/engines/brave.py
parent0ee78c19dd5403560f14a13bbedeb75318ace45d (diff)
[mod] replace js_variable_to_python by js_obj_str_to_python (#2792) (#5477)
This patch is based on PR #2792 (old PR from 2023) - js_obj_str_to_python handle more cases - bring tests from chompjs .. - comment out tests do not pass The tests from chompjs give some overview of what is not implemented. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/brave.py')
-rw-r--r--searx/engines/brave.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/searx/engines/brave.py b/searx/engines/brave.py
index fe8fb616b..75775d1ec 100644
--- a/searx/engines/brave.py
+++ b/searx/engines/brave.py
@@ -134,7 +134,7 @@ from searx.utils import (
eval_xpath,
eval_xpath_list,
eval_xpath_getindex,
- js_variable_to_python,
+ js_obj_str_to_python,
get_embeded_stream_url,
)
from searx.enginelib.traits import EngineTraits
@@ -262,7 +262,7 @@ def response(resp: SXNG_Response) -> EngineResults:
# data: [{type:"data",data: .... ["q","goggles_id"],route:1,url:1}}]
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
js_object = "[{" + extr(resp.text, "data: [{", "}}],") + "}}]"
- json_data = js_variable_to_python(js_object)
+ json_data = js_obj_str_to_python(js_object)
# json_data is a list and at the second position (0,1) in this list we find the "response" data we need ..
json_resp = json_data[1]['data']['body']['response']
@@ -439,9 +439,9 @@ def fetch_traits(engine_traits: EngineTraits):
resp = get('https://search.brave.com/settings')
- if not resp.ok: # type: ignore
+ if not resp.ok:
print("ERROR: response from Brave is not OK.")
- dom = html.fromstring(resp.text) # type: ignore
+ dom = html.fromstring(resp.text)
for option in dom.xpath('//section//option[@value="en-us"]/../option'):
@@ -468,12 +468,12 @@ def fetch_traits(engine_traits: EngineTraits):
resp = get('https://cdn.search.brave.com/serp/v2/_app/immutable/chunks/parameters.734c106a.js')
- if not resp.ok: # type: ignore
+ if not resp.ok:
print("ERROR: response from Brave is not OK.")
- country_js = resp.text[resp.text.index("options:{all") + len('options:') :] # type: ignore
+ country_js = resp.text[resp.text.index("options:{all") + len('options:') :]
country_js = country_js[: country_js.index("},k={default")]
- country_tags = js_variable_to_python(country_js)
+ country_tags = js_obj_str_to_python(country_js)
for k, v in country_tags.items():
if k == 'all':