python获取登录验证码

来源:互联网 发布:期货交易软件下载 编辑:程序博客网 时间:2024/05/21 07:53

根据sessionId下载验证码,通过人工方式识别

import urllib2def get_captcha(captchaUrl, sessionIdKey, sessionIdValue):    """获得验证码图片    通过fiddler分析验证码请求时需要携带的cookie,通常验证码是与某个sessionid绑定的    Args:        captchaUrl: 验证码地址        sessionIdKey: session key        sessionIdValue: session value    """    req = urllib2.Request(captchaUrl)    req.add_header("Cookie","%s=%s" % (sessionIdKey,sessionIdValue))    res = urllib2.urlopen(req)    picture = res.read()    imgpath = "captcha.gif"    with open(imgpath,"wb") as fp:        fp.write(picture)    # 请输入验证码    captchaValue = raw_input("please input captcha:")    return captchaValue
0 0
原创粉丝点击