Nv7-GitHub / googlesearch

A Python library for scraping the Google search engine.
https://pypi.org/project/googlesearch-python/
MIT License
430 stars 110 forks source link

update __init__.py avoiding infinite loop #54

Closed chc-tw closed 1 year ago

chc-tw commented 1 year ago

In certain scenarios, Google may be unable to find any relevant results related to the search term, resulting in an empty search result block. This can be identified by the length of the search result block, which will be equal to zero.

If the search result block is empty, the code will not enter the for loop at line 63. As a result, the value of the start variable will not be changed, causing the program to enter an infinite loop. To prevent this, we need to add a check to verify the length of the search result block and update the value of start accordingly.

Therefore, I recommend adding a condition to check if the length of the search result block is zero, and update the value of start to break out of the loop. This ensures that the program behaves correctly and avoids any potential infinite loops.

Nv7-GitHub commented 1 year ago

Have you tested this and made sure it works?

chc-tw commented 1 year ago

I have tested the updated code extensively in my side project (fake news source searching). It has been used approximately 800 to 1000 times in my side project, and throughout this usage, I have not encountered any bugs or issues and the infinite loop and the infinite loop has not reappeared. While my testing has provided positive results, it's important to note that I have not conducted an exhaustive analysis covering all possible scenarios. However, based on the extensive usage and only minor modifications to the code, I am confident in the correctness of the proposed change.