Handle HTTP 429 rate limiting
masterBy default, yagooglesearch automatically handles HTTP 429 (Too Many Requests) errors by sleeping for http_429_cool_off_time_in_minutes and increasing the wait time by http_429_cool_off_factor on subsequent detections.
If you prefer to manage rate limiting manually, set yagooglesearch_manages_http_429s=False. In this mode, if a 429 is detected, the string "HTTP_429_DETECTED" is appended to the returned list of results. You must check for this string and handle it (e.g., by removing it from the list) to process the URLs found before the block.
import yagooglesearch
client = yagooglesearch.SearchClient(
"site:twitter.com",
tbs="li:1",
verbosity=4,
num=10,
max_search_result_urls_to_return=1000,
minimum_delay_between_paged_results_in_seconds=1,
yagooglesearch_manages_http_429s=False, # Manual management
)
client.assign_random_user_agent()
urls = client.search()
if "HTTP_429_DETECTED" in urls:
print("HTTP 429 detected... it's up to you to modify your search.")
urls.remove("HTTP_429_DETECTED")
for url in urls:
print(url)