简体   繁体   中英

Using Chromedriver with Google Images download

I am trying to run the following code to pull in some images:

from google_images_download import google_images_download   #importing the library

response = google_images_download.googleimagesdownload()   #class instantiation

arguments = {"keywords":"foxes, shiba inu outside","limit":2000,"print_urls":True}   #creating list of arguments
paths = response.download(arguments)   #passing the arguments to the function
print(paths)   #printing absolute paths of the downloaded images

Because I am trying to do over 100 images I am getting a message saying

Looks like we cannot locate the path the 'chromedriver' (use the '--chromedriver' argument to specify the path to the executable.) or google chrome browser is not installed on your machine (exception: expected str, bytes or os.PathLike object, not NoneType)

I am unsure how to integrate the chromedriver piece into my code and set the path. I searched around but I cannot find a clear answer. I tried adding the line

browser = webdriver.Chrome(executable_path=r"/Users/jerelnovick/Desktop/Projects/Image_Recognition/chromedriver.exe")

as I read in one post but that gave me a message saying

WebDriverException: Message: 'Image_Recognitionchromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

I am using a Mac.

There are some additional steps to take to get more than 100 images. From the docs :

If you would want to download more than 100 images per keyword, then you will need to install 'selenium' library along with 'chromedriver' extension.

And then your arguments will need to be updated as:

arguments = {"keywords":"foxes, shiba inu outside",
             "limit":2000,
             "print_urls":True,
             "chromedriver":"/Users/jerelnovick/Desktop/Projects/Image_Recognition/chromedriver"}

Also make sure the chromedriver you download is the proper one for mac.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM