12306/inter/GetRandCode.py

85 lines
2.6 KiB
Python
Raw Normal View History

# coding=utf-8
from PIL import Image
from verify.localVerifyCode import verify
2018-12-25 03:47:20 +00:00
def getRandCode(is_auto_code, auto_code_type, result):
"""
识别验证码
:return: 坐标
"""
try:
if is_auto_code:
if auto_code_type == 1:
print(u"打码兔已关闭, 如需使用自动识别,请使用如果平台 auto_code_type == 2")
return
if auto_code_type == 2:
Result = verify(result)
return codexy(Ofset=Result, is_raw_input=False)
else:
2019-01-07 09:48:41 +00:00
img = Image.open('./tkcode.png')
img.show()
return codexy()
2018-12-25 06:40:49 +00:00
except Exception as e:
print(e)
def codexy(Ofset=None, is_raw_input=True):
"""
获取验证码
:return: str
"""
if is_raw_input:
2018-08-31 16:24:40 +00:00
print(u"""
*****************
2018-08-31 16:28:48 +00:00
| 1 | 2 | 3 | 4 |
2018-08-31 16:24:40 +00:00
*****************
2018-08-31 16:28:48 +00:00
| 5 | 6 | 7 | 8 |
2018-08-31 16:24:40 +00:00
*****************
""")
2019-01-07 09:48:41 +00:00
print(u"验证码分为8个对应上面数字例如第一和第二张输入1, 2 如果开启cdn查询的话会冲掉提示直接鼠标点击命令行获取焦点输入即可不要输入空格")
2019-01-08 02:22:46 +00:00
print(u"如果是linux无图形界面请使用自动打码is_auto_code: True")
2019-01-08 09:04:40 +00:00
print(u"如果没有弹出验证码请手动双击根目录下的tkcode.png文件")
2019-09-01 04:41:25 +00:00
Ofset = input(u"输入对应的验证码: ")
if isinstance(Ofset, list):
select = Ofset
else:
Ofset = Ofset.replace("", ",")
select = Ofset.split(',')
post = []
offsetsX = 0 # 选择的答案的left值,通过浏览器点击8个小图的中点得到的,这样基本没问题
offsetsY = 0 # 选择的答案的top值
for ofset in select:
if ofset == '1':
2019-01-06 04:26:08 +00:00
offsetsY = 77
offsetsX = 40
elif ofset == '2':
2019-01-06 04:26:08 +00:00
offsetsY = 77
offsetsX = 112
elif ofset == '3':
2019-01-06 04:26:08 +00:00
offsetsY = 77
offsetsX = 184
elif ofset == '4':
2019-01-06 04:26:08 +00:00
offsetsY = 77
offsetsX = 256
elif ofset == '5':
2019-01-06 04:26:08 +00:00
offsetsY = 149
offsetsX = 40
elif ofset == '6':
2019-01-06 04:26:08 +00:00
offsetsY = 149
offsetsX = 112
elif ofset == '7':
2019-01-06 04:26:08 +00:00
offsetsY = 149
offsetsX = 184
elif ofset == '8':
2019-01-06 04:26:08 +00:00
offsetsY = 149
offsetsX = 256
else:
pass
post.append(offsetsX)
post.append(offsetsY)
randCode = str(post).replace(']', '').replace('[', '').replace("'", '').replace(' ', '')
print(u"验证码识别坐标为{0}".format(randCode))
return randCode