12306/inter/GetPassCodeNewOrderAndLogin.py

23 lines
693 B
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# coding=utf-8
def getPassCodeNewOrderAndLogin(session, imgType):
"""
下载验证码
:param session:
:param imgType: 下载验证码类型login=登录验证码,其余为订单验证码
:return:
"""
if imgType == "login":
codeImgUrl = session.urls["getCodeImg"]
else:
codeImgUrl = session.urls["codeImgByOrder"]
print (u"下载验证码...")
img_path = './tkcode'
result = session.httpClint.send(codeImgUrl)
try:
print(u"下载验证码成功")
open(img_path, 'wb').write(result)
except OSError:
print (u"验证码下载失败可能ip被封确认请手动请求: {0}".format(codeImgUrl))