近期公司安排了几份爬虫项目的工作, 经过几天的奋战, 基本功能都已实现, 一时间增加了对爬虫的兴趣.
为了进一步提升自己, 闲暇时间摸索着学习下爬虫工作中遇到的深度学习的知识
爬虫之路很坎坷, 有时间就会整理些笔记, 供大家学习&爬坑
一. 生成一批验证码数据
import random
import time
from captcha.image import ImageCaptcha
captcha_list = list('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
captcha_size = 4
def main():
for i in range(2):
image = ImageCaptcha()
image_text = ''.join(random.sample(captcha_list, captcha_size))
image_path = './datasets/train/{}.{}.png'.format(image_text, int(time.time()))
image.write(image_text, image_path)
if __name__ == '__main__':
main()
这里用到了一个captcha的包, 安装
pip install captcha
执行程序如遇到 The _imagingft C module is not installed 报错信息
我的处理方式是卸载 Pillow和刚装的captcha包, 然后重装
pip uninstall Pillow
pip uninstall captcha
pip install Pillow
pip install captcha