Skip to content

Commit

Permalink
Bugfix iterating if max_results is None
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed Dec 22, 2024
1 parent 5ac8a6d commit f7011c3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions duckduckgo_search/duckduckgo_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _text_api(
return results
else:
next_page_url = row.get("n")
if not next_page_url:
if not next_page_url or not max_results:
return results
payload["s"] = next_page_url.split("s=")[1].split("&")[0]
return results
Expand Down Expand Up @@ -365,7 +365,7 @@ def _text_html(
return results

npx = tree.xpath('.//div[@class="nav-link"]')
if not npx:
if not npx or not max_results:
return results
next_page = npx[-1] if isinstance(npx, list) else None
if isinstance(next_page, _Element):
Expand Down Expand Up @@ -447,7 +447,7 @@ def _text_lite(
return results

next_page_s = tree.xpath("//form[./input[contains(@value, 'ext')]]/input[@name='s']/@value")
if not next_page_s:
if not next_page_s or not max_results:
return results
elif isinstance(next_page_s, list):
payload["s"] = str(next_page_s[0])
Expand Down Expand Up @@ -539,7 +539,7 @@ def images(
if max_results and len(results) >= max_results:
return results
next = resp_json.get("next")
if next is None:
if next is None or not max_results:
return results
payload["s"] = next.split("s=")[-1].split("&")[0]

Expand Down Expand Up @@ -609,7 +609,7 @@ def videos(
if max_results and len(results) >= max_results:
return results
next = resp_json.get("next")
if next is None:
if next is None or not max_results:
return results
payload["s"] = next.split("s=")[-1].split("&")[0]

Expand Down Expand Up @@ -681,7 +681,7 @@ def news(
return results

next = resp_json.get("next")
if next is None:
if next is None or not max_results:
return results
payload["s"] = next.split("s=")[-1].split("&")[0]

Expand Down

0 comments on commit f7011c3

Please sign in to comment.