使用关键字搜索和下载图像。

python-pisces的Python项目详细描述


PyPI

为什么要用双鱼座?

本课题来源于图像数据集对算法训练的需求。

像谷歌这样的图像搜索引擎现在已经相当强大了。如果我们能利用它们,它们就足够了。 但是,他们没有为我们提供方便的API

双鱼座使用selenuim,它可以与chromedriver一起下载我们需要的图像。 双鱼座支持这些搜索引擎:谷歌、雅虎、必应、百度(中国)以及未来更多的主流引擎。

为什么要用双鱼座?(中文)

项目名称

谷歌,谷歌,谷歌美国石油学会标准。

双鱼座双鱼座

安装

首先,确保您的计算机上安装了chrome浏览器。 否则,selenium将给出“selenium.common.exceptions.webdriverexception:message:unknown error:cannot find chrome binary”。

如果您在没有接口的服务器(例如,CentOS)上工作,也可以按照以下步骤进行安装:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
yum -y localinstall google-chrome-stable_current_x86_64.rpm

使用pip:

pip install python-pisces

源代码:

git clone https://github.com/wolfhong/python-pisces.git
cd python-pisces

pip install -r requirements.txt
export PYTHONPATH=./
python scripts/update_chromedriver.py  # download newest chromedriver according to platform
python setup.py install

除了chrome之外,还可以使用firefox。但是,您需要为firefox做额外的设置。您必须下载geckodriver并将其放入您的$PATH中,这有助于Selenium与Firefox浏览器进行交互。

双鱼座使用Chrome作为默认浏览器。你不必下载你自己,因为双鱼座有内置的。

双鱼座首先在其软件包中的pisces/tools/中找到chromedriver(用于chrome)或geckodriver(用于firefox)。如果不是,则在$PATH中找到它。

控制台命令

一旦您安装了双鱼座,您就可以轻松地使用它按关键字搜索和下载图像:

$ pisces -e google -w 8 -n 500 fire "kitchen fire" -o ./output

上面的命令将启动chromedriver,然后用它的图像搜索引擎google“fire”和“kitchen fire”, 并行下载带有8个线程的映像,然后将这些映像还原到“./output”目录中。

如果您在中国,建议您使用-e baidu-e google实例(默认值),因为有些网络问题。(中国)

image

使用pisces -h显示用法:

    usage: command.py [-h] [-q] [--display] [-e ENGINE] [-w WORKERS] [-n NUMBER]                  [-o OUTPUT_DIR] [-v]                  [keywords [keywords ...]]    Use keywords to search for and download images.    positional arguments:      keywords              keywords to search for images    optional arguments:      -h, --help            show this help message and exit      -q, --quiet           quiet (no output)      --display             start up browser with a graphical display, default to no      -e ENGINE, --engine ENGINE                            the image search engine you want to use, default to                            google. select within [google, bing, yahoo, baidu]      -b BROWSER, --browser BROWSER                            the browser you have installed, default to chrome.                            select within [chrome, firefox]      -w WORKERS, --workers WORKERS                            the number of threads when downloading images, default                            to cpu core count      -n NUMBER, --number NUMBER                            the max number of images you want to download, default                            to 100      -o OUTPUT_DIR, --output_dir OUTPUT_DIR                            destination to store downloaded images, default to                            ./output      -v, --version         print the version and exit

双鱼座可以在这些平台上工作:windows、linux、mac,而且经过了测试。 如果没有,欢迎您来file an issue

更多示例:

    $ pisces "kitchen fire""forest fire"    $ pisces -n500 "厨房火灾""森林火灾"    $ pisces -e baidu -n500 -o path-to-output 火灾 水灾

代码示例

双鱼座也可以包含在你的项目中:

frompiscesimportPisces# recommended to use `with`:withPisces(quiet=False,headless=False)asclient:output_dir='./output_water/'client.download_by_word('water',output_dir,engine='google',image_count=20)# or call `close()` handly:client=Pisces(quiet=False,headless=True,workers=4,browser='chrome')output_dir='./output_fire/'client.download_by_word('fire',output_dir,engine='baidu',image_count=20)client.close()

提示

  • 代码使用selenium。更多信息请查看ReadTheDocs
  • 如果您在中国,建议您使用-e baidu-e google实例(默认值),因为有些网络问题。

关于

双鱼座只是一个按关键字搜索和下载图像的工具,使用谷歌、必应、百度等图像搜索引擎。 我希望它能对你有所帮助

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java w.a.UsernamePasswordAuthenticationFilter:尝试对用户进行身份验证时发生内部错误(错误11759)   如何使用Java的3D库?   java我怎样才能知道JitsiMeetActivity是否存在?   java从类路径加载DLL   amazon s3如何使用java在s3中组合策略?   java无法使gwtsyncproxy工作   java如何列出所有默认音乐播放器并打开一个   如何为java调用程序声明返回类型为“void”的Kotlin Lambda?   java RDBMS结果缓存与应用程序级缓存?   java实例化抽象类解决方案   java如何在JWebUnit和JUnit4中使用JUnitPerf?   java getClass()在枚举中使用构造函数时打印二进制格式   在Java中解密defuse/phpencryption Crypto::encryptWithPassword()   java从命令行运行RefactoringMiner   java阻止某些图形重新绘制   在gradle中有两个或多个根的java构建多模块项目