做验证码识别算法的时候,最重要的就是大量可以用于训练的验证码图片,所以,快捷的获取大量验证码图片就很有必要,于是写了个快速获取大量验证码的模块,稍作修改也可以用于下载其它的图片
代码:
# -*- coding: utf-8 -*-
import requests
import time
def get_vcode(nums):
nums = int(nums)
for num in range(1,nums+1):
try:
base_url = "图片url"
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
}
response = requests.get(url=base_url, headers=headers)
time.sleep(0.05)
with open(r"保存路径\{}.jpg".format(num), 'wb', ) as fp:
fp.write(response.content)
except Exception as e:
print('error:{}'.format(e))
pass
if __name__ == '__main__':
nums = input("请输入要获取的数量:")
get_vcode(nums)