Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search() gets stuck on infinite "while loop" if the search term has zero results #34

Closed
Tomz295 opened this issue Jun 16, 2022 · 2 comments

Comments

@Tomz295
Copy link

Tomz295 commented Jun 16, 2022

start = 0
while start < num_results:
# Send request
resp = _req(escaped_term, num_results-start, lang, start, proxies)
# Parse
soup = BeautifulSoup(resp.text, 'html.parser')
result_block = soup.find_all('div', attrs={'class': 'g'})
for result in result_block:
# Find link, title, description
link = result.find('a', href=True)
title = result.find('h3')
description_box = result.find('div', {'style': '-webkit-line-clamp:2'})
if description_box:
description = description_box.find('span')
if link and title and description:
start += 1
if advanced:
yield SearchResult(link['href'], title.text, description.text)
else:
yield link['href']

Code cannot exit the while loop if the value of start never goes up, and the value of start only ever goes up if a valid result is yielded.
For search terms that have zero results, this results on the code getting stuck trying to find something forever.

@Tomz295 Tomz295 changed the title search() gets stuck on infinite "while loop" if the search term returns no results search() gets stuck on infinite "while loop" if the search term has zero results Jun 16, 2022
Nv7-GitHub added a commit that referenced this issue Apr 27, 2023
@binhex
Copy link

binhex commented May 23, 2023

Any chance this can get merged in and released?

@Nv7-GitHub
Copy link
Owner

This has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants