最终的架构.png
所以,我在爬虫框架中封装了一个工具方法,只需要传入图片的url地址就能够返回验证码的内容。
/**
* 返回验证码的内容
* @param imageUrl 验证码的url
* @return
*/
public static String getCaptcha(String imageUrl)
测试几张图片
System.out.println(Utils.getCaptcha("http://47.97.7.119/qianmou/images/captcha/1.png"));
System.out.println(Utils.getCaptcha("http://47.97.7.119/qianmou/images/captcha/2.png"));
System.out.println(Utils.getCaptcha("http://47.97.7.119/qianmou/images/captcha/3.png"));
System.out.println(Utils.getCaptcha("http://47.97.7.119/qianmou/images/captcha/4.png"));
System.out.println(Utils.getCaptcha("http://47.97.7.119/qianmou/images/captcha/5.png"));
System.out.println(Utils.getCaptcha("http://47.97.7.119/qianmou/images/captcha/6.png"));
执行结果:
862FF
7FA88
F3686
6D964
FE9FC
6494A
经过测试后,发现只有第一个验证码是识别错误的,其余五个都能够正确地识别出验证码中的数字和字母。
第一个验证码正确的值应该是862DF,而不是862FF。