Skip to content

Commit

Permalink
Update mullvad_leta.py to account for img_elem
Browse files Browse the repository at this point in the history
A recent update from Mullvad Leta introduced the img_elem. This update
broke the existing logic. Now, by checking the length of the dom_result
to see if it was included in the return results, we can handle the logic
accordingly.
  • Loading branch information
glanham-jr authored and return42 committed Jul 15, 2024
1 parent 2039060 commit 9a4fa7c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions searx/engines/mullvad_leta.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ def request(query: str, params: dict):


def extract_result(dom_result: list[html.HtmlElement]):
[a_elem, h3_elem, p_elem] = dom_result
# Infoboxes sometimes appear in the beginning and will have a length of 0
if len(dom_result) == 3:
[a_elem, h3_elem, p_elem] = dom_result
elif len(dom_result) == 4:
[_, a_elem, h3_elem, p_elem] = dom_result
else:
return None

return {
'url': extract_text(a_elem.text),
'title': extract_text(h3_elem),
Expand All @@ -139,9 +146,9 @@ def extract_result(dom_result: list[html.HtmlElement]):
def extract_results(search_results: html.HtmlElement):
for search_result in search_results:
dom_result = eval_xpath_list(search_result, 'div/div/*')
# sometimes an info box pops up, will need to filter that out
if len(dom_result) == 3:
yield extract_result(dom_result)
result = extract_result(dom_result)
if result is not None:
yield result


def response(resp: Response):
Expand Down

0 comments on commit 9a4fa7c

Please sign in to comment.