欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

Python大批量搜索引擎图像爬虫工具详解

时间:2021-09-24 10:57:11|栏目:Python代码|点击:

python图像爬虫包

最近在做一些图像分类的任务时,为了扩充我们的数据集,需要在搜索引擎下爬取额外的图片来扩充我们的训练集。搞人工智能真的是太难了😭,居然还要会爬虫。当然网上也有许多python写的爬虫工具,当然,用多了就知道,这些爬虫工具不是不能进行多关键字的爬虫就是用不了,或者是一会就被网站检测到给停止了,最后发现了一款非常好用的python图像爬虫库icrawler,直接就能通过pip进行安装,使用时几行代码就能搞定,简直不要太爽。
话不多说,附上安装命令:

pip install icrawler

下面附上我爬虫的代码:

from icrawler.builtin import BaiduImageCrawler 
from icrawler.builtin import BingImageCrawler 
from icrawler.builtin import GoogleImageCrawler 
#需要爬虫的关键字
list_word = ['抽烟 行人','吸烟 行人','接电话 行人','打电话 行人', '玩手机 行人']
for word in list_word:
  #bing爬虫
  #保存路径
  bing_storage = {'root_dir': 'bing\\'+word}
  #从上到下依次是解析器线程数,下载线程数,还有上面设置的保存路径
  bing_crawler = BingImageCrawler(parser_threads=2,
                  downloader_threads=4,
                  storage=bing_storage)
  #开始爬虫,关键字+图片数量
  bing_crawler.crawl(keyword=word,
            max_num=2000)

  #百度爬虫
  # baidu_storage = {'root_dir': 'baidu\\' + word}
  # baidu_crawler = BaiduImageCrawler(parser_threads=2,
  #                  downloader_threads=4,
  #                  storage=baidu_storage)
  # baidu_crawler.crawl(keyword=word,
  #           max_num=2000)


  # google爬虫
  # google_storage = {'root_dir': '‘google\\' + word}
  # google_crawler = GoogleImageCrawler(parser_threads=4,
  #                  downloader_threads=4,
  #                  storage=google_storage)
  # google_crawler.crawl(keyword=word,
  #           max_num=2000)

这个爬虫库能够实现多线程,多搜索引擎(百度、必应、谷歌)的爬虫,当然谷歌爬虫需要梯子。这里展示的是基于必应的爬虫,百度和谷歌的代码也在下面,只不过被我屏蔽掉了,当然也可以三个同时全开!这样的python爬虫库用起来简直不要太爽。

上一篇:Random 在 Python 中的使用方法

栏    目:Python代码

下一篇:Python中的文件和目录操作实现代码

本文标题:Python大批量搜索引擎图像爬虫工具详解

本文地址:http://www.codeinn.net/misctech/176965.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有