根據sessionId下載驗證碼,通過人工方式識別
import urllib2
def 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