hardikvasa / google-images-download

Python Script to download hundreds of images from 'Google Images'. It is a ready-to-run code!
MIT License
8.58k stars 2.11k forks source link

Getting error when we pass double quoted search terms with "extract_metadata" = True. #170

Open thamizhchelvan opened 6 years ago

thamizhchelvan commented 6 years ago

Hello,

Thanks for the nice work. I am getting error, when I pass double quoted search terms with "extract_metadata" = True.

Payload: {"keywords":"\"siberian husky\"","limit":1,"print_urls":True,"extract_metadata":True,"usage_rights":"labeled-for-reuse","no_directory":True, "no_numbering":True}

Error:


Traceback (most recent call last):
  File "googleImage.py", line 6, in <module>
    gresponse = response.download(arguments)
  File "AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\google_images_download\google_images_download.py", line 858, in download
    json_file = open("logs/"+search_keyword[i]+".json", "w")
OSError: [Errno 22] Invalid argument: 'logs/"siberian husky".json'
hardikvasa commented 5 years ago

@thamizhchelvan sorry for the delayed response. Were you able to get around this issue? what OS version and flavor you are testing this on? Also why not just use keywords without extra quotes like this "keywords":"siberian husky" ?

i however tested the CLI equivalent of what you re trying python3 google_images_download.py -k "\"siberian husky\"" -l 1 --print_urls --extract_metadata --usage_rights 'labeled-for-reuse' --no_directory --no_numbering

but i did not get any error. Maybe the os doesn't like the .json file name to have double quotes?

thamizhchelvan commented 5 years ago

@hardikvasa ,

Nope, still having the same issue. I am using double quotes to match the exact terms inside the quotes. I am using Windows 7.

WR-BillRich commented 5 years ago

How about editing the code so that the directory name (dir_name) only contains code that is compatible with windows directory naming? image By using the above function, we change the strip the illegal symbol from dir_name in both create_directories def and get_all_item def image image