RiddlerQ / simple_image_download

Python script that lets you auto download images from google images using tags
MIT License
145 stars 54 forks source link

Goes into infinite loop if the google image search "did not match any image results" #10

Open achintb2 opened 3 years ago

achintb2 commented 3 years ago

On Line 37, if the search query does NOT return any results on google images, python goes into an infinite loop.

` 35 try: 36 new_line = raw_html.find('"https://', end_object + 1) ---> 37 end_object = raw_html.find('"', new_line + 1) 38 39 buffor = raw_html.find('\', new_line + 1, end_object)

KeyboardInterrupt: `

Maybe find the string "did not match any image results" in html file first and raise error?

amin-213 commented 3 years ago

It works after little changes...

Line31: n_new_line = 0 if raw_html.find("did not match any image results") != -1: return([]) while j < limit: while (True): try: new_line = raw_html.find('"https://', end_object + 1) if new_line > n_new_line: n_new_line = new_line if new_line < n_new_line: return([]) end_object = raw_html.find('"', new_line + 1) buffor = raw_html.find('\', new_line + 1, end_object) if buffor != -1: object_raw = (raw_html[new_line + 1:buffor]) else: object_raw = (raw_html[new_line + 1:end_object]) if any(extension in object_raw for extension in extensions): break except Exception as e: break