From 8b01679e8fc0558cde1da1d6437ca72ad20254e4 Mon Sep 17 00:00:00 2001 From: vojkovic Date: Sat, 5 Sep 2026 13:41:56 +0000 Subject: [fix] engines: update brave images/videos parser and news xpath --- searx/engines/brave.py | 22 +++++++++++----------- searx/utils.py | 12 ++++++------ 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'searx') diff --git a/searx/engines/brave.py b/searx/engines/brave.py index de0a108b0..8d0994227 100644 --- a/searx/engines/brave.py +++ b/searx/engines/brave.py @@ -248,13 +248,13 @@ def extract_json_data(text: str) -> dict[str, t.Any]: # node_ids: [0, 19], # data: [{type:"data",data: .... ["q","goggles_id"],route:1,url:1}}] # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - text = text[text.index(" EngineResults: res = EngineResults() dom = html.fromstring(resp.text) - for result in eval_xpath_list(dom, "//div[contains(@class, 'results')]//div[@data-type='news']"): - url = eval_xpath_getindex(result, ".//a[contains(@class, 'result-header')]/@href", 0, default=None) + for result in eval_xpath_list(dom, "//div[@data-type='news']"): + url = eval_xpath_getindex(result, ".//a/@href", 0, default=None) if url is None: continue - title = eval_xpath_list(result, ".//span[contains(@class, 'snippet-title')]") - content = eval_xpath_list(result, ".//p[contains(@class, 'desc')]") - thumbnail = eval_xpath_getindex(result, ".//div[contains(@class, 'image-wrapper')]//img/@src", 0, default="") + title = eval_xpath_list(result, ".//div[contains(@class, 'title')]") + content = eval_xpath_list(result, ".//div[contains(@class, 'description')]") + thumbnail = eval_xpath_getindex(result, ".//a[contains(@class, 'thumbnail')]//img/@src", 0, default="") item = res.types.LegacyResult( template="default.html", diff --git a/searx/utils.py b/searx/utils.py index 9c70c8cc4..b03f8f057 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -735,13 +735,13 @@ def js_obj_str_to_json_str(js_obj_str: str) -> str: if in_string == "'": p = p.replace('"', r'\"') parts[i] = p - # deal with the sequence blackslash then quote - # since js_obj_str splits on quote, we detect this case: - # * the previous part ends with a black slash - # * the current part is a single quote - # when detected the blackslash is removed on the previous part + # drop a trailing \ that was escaping the quote + # leave it if it has been escaped twice as a literal i.e. two \ and ' in a row if blackslash_just_before and p[:1] == "'": - parts[i - 1] = parts[i - 1][:-1] + prev = parts[i - 1] + num_backslashes = len(prev) - len(prev.rstrip("\\")) + if num_backslashes % 2 == 1: + parts[i - 1] = prev[:-1] elif in_string is None and p in ('"', "'", "`"): # we are not in string but p is string delimiter -- cgit v1.2.3