简体   繁体   English

将 Chromedriver 与 Google 图片一起使用 下载

[英]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因为我正在尝试制作 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”的路径(使用“--chromedriver”参数指定可执行文件的路径。)或您的计算机上未安装 google chrome 浏览器(例外:预期的 str、bytes 或 os.PathLike object,不是无类型)

I am unsure how to integrate the chromedriver piece into my code and set the path.我不确定如何将 chromedriver 集成到我的代码中并设置路径。 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. WebDriverException:消息:“Image_Recognitionchromedriver.exe”可执行文件需要在 PATH 中。 Please see https://sites.google.com/a/chromium.org/chromedriver/home请参阅https://sites.google.com/a/chromium.org/chromedriver/home

I am using a Mac.我正在使用 Mac。

There are some additional steps to take to get more than 100 images.要获得 100 多张图像,还需要采取一些额外的步骤。 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.如果您想为每个关键字下载超过 100 张图片,那么您需要安装“selenium”库以及“chromedriver”扩展程序。

And then your arguments will need to be updated as:然后您的arguments将需要更新为:

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.还要确保您下载的 chromedriver 是适用于 mac 的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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