本文来源吾爱破解论坛
本帖最后由 17788210295 于 2019-7-24 18:23 编辑
今天研究半天 验证码校验已经通过,但是卡在了关键的登录一步,一直提示账号未登录
有没有大神知道12306新增了哪一个隐藏的post请求 网络存在问题是什么导致的
源码;
[Python] 纯文本查看 复制代码
import requests from PIL import Image import json answer = { "1": "40,40", "2": "110,40", "3": "180,40", "4": "260,40", "5": "40,120", "6": "110,120", "7": "180,120", "8": "260,120", } head = { 'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299", "Host": "kyfw.12306.cn", "Referer": "https://kyfw.12306.cn/otn/resources/login.html" } def get_img_code(): img_url = 'https://kyfw.12306.cn/passport/captcha/captcha-image?login_site=E&module=login&rand=sjrand' img = session.get(url=img_url, headers=head).content with open('code.jpg', 'wb') as f: f.write(img) def check_img(): check_url = 'https://kyfw.12306.cn/passport/captcha/captcha-check' img = Image.open('code.jpg').show() print("+----------+----------+----------+----------+") print("| 1 | 2 | 3 | 4 |") print("|----------|----------|----------|----------|") print("| 5 | 6 | 7 | 8 |") print("+----------+----------+----------+----------+") input_code = input("请在1—8中选择输入验证图片编号,以半角','隔开。(例如:1,3,5):") answer_code = '' try: for i in input_code.split(','): answer_code += ',' + answer[i] if (i is not input_code[0]) else answer[i] except Exception as e: print('输入错误请重新输入!') check_img() data = { 'answer': answer_code, 'login_site': 'E', 'rand': 'sjrand', } check_result = session.post(url=check_url, data=data, headers=head).text check_result = json.loads(check_result) print(check_result) if check_result['result_code'] == '4': print('*' * 20 + '验证码正确' + '*' * 20) login(answer_code) else: get_img_code() check_img() def login(answer_code): # name = input('账号:') # pwd = input('密码:') name = '*********' pwd = '*********' login_url = 'https://kyfw.12306.cn/passport/web/login' formdata = { 'username': name, 'password': pwd, 'appid': 'otn', 'answer': answer_code } login_result = session.post(url=login_url, data=formdata, headers=head) login_result.encoding='utf-8' print(login_result.text) with open('3.html','w',encoding='utf-8') as f: f.write(login_result.text) # def user_login(): # url='https://kyfw.12306.cn/otn/login/userLogin' # page=requests.get(url=url).text # print(page) # def check_useer(): # url = 'https://kyfw.12306.cn/otn/login/checkUser' # data = { # '_json_att': '' # } # requests.post(url=url, data=data,headers=head) def uamtk(): url = 'https://kyfw.12306.cn/passport/web/auth/uamtk' data = { 'appid': 'otn', } uamtk_page = session.post(url=url, data=data, headers=head).text print(uamtk_page) if __name__ == '__main__': session = requests.Session() get_img_code() check_img() uamtk()
Snipaste_2019-07-24_18-15-27.jpg (15.71 KB, 下载次数: 4)
下载附件 保存到相册
2019-7-24 18:19 上传
登录页面
Snipaste_2019-07-24_18-12-43.jpg (12.99 KB, 下载次数: 0)
下载附件 保存到相册
2019-7-24 18:18 上传
post登录网址
Snipaste_2019-07-24_18-15-14.jpg (7.95 KB, 下载次数: 1)
下载附件 保存到相册
2019-7-24 18:18 上传
post验证码 后响应
版权声明:
本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。