在一篇文章中看到这个库,随手就用了用,总体感觉还不错。
直接使用 pip install icrawler
就能安装使用,还是挺方便的。
我觉得这个库的一个优势就是很方便,没有过多的代码,只需要设置好关键字一些关键参数就行。并且该库可以自动的使用多线程。
我是使用jupyter notebook测试的。
代码如下
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=200)
#百度爬虫
# 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)
总体而言:方便,快捷。有兴趣的可以找一找官方教程。内部实现其实也是不难的,有时间可以自己实现一下。
仅供个人学习使用,侵删