将 Chromedriver 与 Google 图片下载结合使用

Using Chromedriver with Google Images download

我正在尝试 运行 以下代码来提取一些图像:

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

因为我正在尝试制作超过 100 张图像,所以我收到一条消息说

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)

我不确定如何将 chromedriver 部分集成到我的代码中并设置路径。我四处搜寻,但找不到明确的答案。我尝试添加行

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

正如我在一篇 post 中读到的,但那给了我一条消息说

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

我正在使用 Mac。

要获得超过 100 张图像,还需要执行一些额外的步骤。来自 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.

然后您的 arguments 需要更新为:

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

还要确保您下载的 chromedriver 是 mac 的正确驱动程序。