12306登录python_Python模拟登录12306
#!/usr/bin/python#-*- coding: utf-8 -*-
importre;importsys;importcookielib;importurllib;importurllib2;importoptparse;importjson;importhttplib2;
reload(sys)
sys.setdefaultencoding(‘utf8‘);defLogin():
cj=cookielib.CookieJar();
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj));
urllib2.install_opener(opener);print "--------------[step1] to get cookie";
Url= "https://kyfw.12306.cn/otn/login/init";
resp=urllib2.urlopen(Url);for index, cookie inenumerate(cj):print ‘[‘,index, ‘]‘,cookie;print "--------------[step2] to get code";
Url2= "https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand";
resp2=urllib2.urlopen(Url2);#respInfo2 = resp2.info();
#print "respInfo=",respInfo2;
with open("code.png", "wb") as image:
image.write(resp2.read())
codeStr=sys.stdin.readline();
codeStr= codeStr[:-1]print "--------------[step3] to check code";
ajax_url= "https://kyfw.12306.cn/otn/passcodeNew/checkRandCodeAnsyn";
dc={‘randCode‘: codeStr,‘rand‘ : "sjrand"};
request=urllib2.Request(ajax_url, urllib.urlencode(dc))
request.add_header("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
request.add_header(‘X-Requested-With‘,‘XMLHttpRequest‘)
request.add_header(‘User-Agent‘,‘Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36‘)
request.add_header(‘Referer‘,‘https://kyfw.12306.cn/otn/login/init‘)
request.add_header(‘Accept‘,‘*/*‘)
request.add_header(‘Accept-Encoding‘,‘gzip, deflate‘)
f=urllib2.urlopen(request)print(f.read())print "--------------[step4] to login";
LoginUrl= "http://kyfw.12306.cn/otn/login/loginAysnSuggest";
dc={‘randCode‘: codeStr,‘userDTO.password‘ : "sunyuke1989",‘loginUserDTO.user_name‘: ""};
req=urllib2.Request(LoginUrl, urllib.urlencode(dc));
req.add_header(‘Content-Type‘, "application/x-www-form-urlencoded");
req.add_header(‘X-Requested-With‘,‘XMLHttpRequest‘);
req.add_header(‘Origin‘,‘https://kyfw.12306.cn‘);
req.add_header(‘Referer‘,‘https://kyfw.12306.cn/otn/login/init‘);
req.add_header(‘Accept‘,‘*/*‘);
req.add_header(‘Accept-Encoding‘,‘gzip, deflate‘);
req.add_header(‘Connection‘,‘keep-live‘);
request.add_header(‘User-Agent‘,‘Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36‘)
resp=urllib2.urlopen(req);print(resp.read().encode(‘gb18030‘));
LoginingUrl= "https://kyfw.12306.cn/otn/login/userLogin";
req= urllib2.Request(LoginingUrl, "");print "--------------[step5] to QueryUserInfo";
LoginingUrl= "https://kyfw.12306.cn/otn/modifyUser/initQueryUserInfo";
req= urllib2.Request(LoginingUrl, "");
resp=urllib2.urlopen(req);
info=resp.read();print(resp.read().encode(‘gb18030‘));if __name__=="__main__":
Login();
12306登录python_Python模拟登录12306相关推荐
- python模拟qq空间登录_模拟登录QQ空间
# coding=utf-8 from selenium import webdriver # 模拟登录QQ空间 def Start_Login(): # 这个是chormedriver的地址 dri ...
- php 提取登录QQsid_php模拟登录qq邮箱(curl命令详解)
header("Content-type:text/html;charset=utf-8"); $cookie_file = dirname(__FILE__)."/co ...
- php 模拟微信登录,PHP 模拟登录微信公众平台
用户提问 <?phpclass wechat{ private $username; private $password; private $cookie; public function __ ...
- python模拟qq空间登录_模拟登录系列 | QQ空间模拟登录
原文链接模拟登录系列 | QQ空间模拟登录mp.weixin.qq.com 本系列所有代码均在这CharlesPikachu/DecryptLogingithub.com 原理简介 这里,我们简单 ...
- python qq空间登录_模拟登录QQ空间
# coding=utf-8 from selenium import webdriver # 模拟登录QQ空间 def Start_Login(): # 这个是chormedriver的地址 dri ...
- python爬虫实战(四)--------豆瓣网的模拟登录(模拟登录和验证码的处理----scrapy)...
在利用scrapy框架爬各种网站时,一定会碰到某些网站是需要登录才能获取信息. 这两天也在学习怎么去模拟登录,通过自己码的代码和借鉴别人的项目,调试成功豆瓣的模拟登录,顺便处理了怎么自动化的处理验证码 ...
- 12306登录python_python tcp登录注册_12306注册登录入口
如何基于Python写一个TCP反向连接后门 400x500 - 203KB - PNG 如何基于Python写一个TCP反向连接后门 690x488 - 217KB - PNG 如何基于Python ...
- python模拟登录12306_Python模拟登录12306的方法
#!/usr/bin/python # -*- coding: utf-8 -*- import re; import sys; import cookielib; import urllib; im ...
- python模拟登录12306_python模拟登录12306缺少cookies
[Python] 纯文本查看 复制代码API_GET_BROWSER_DEVICE_ID = '此处填接口地址' def request_device_id(self): ""&q ...
最新文章
- NPM:Cannot read property 'pause' of undefined
- c语言程序设计第1章
- laravel 先排序后分组怎么写_插入排序的故事
- UIButton的几种触发方式
- 嵌入式电路设计(电路仿真)
- 测试平台的发展与未来趋势
- 在Oracle中查询表的大小、表的占用情况和表空间的大小
- python交互式程序设计导论小测验答案_最新网课答案2021学堂在线Python 交互式程序设计导论...
- 1.4.1用空间向量研究直线、平面的位置关系教学设计
- 解决maven不能自动导入ojdbc14的问题
- CCNA考试题库中英文翻译版及答案2
- 【网络科普】NAS和SAN - 网络附加存储和存储区域网络
- 最新国民人均年薪出炉,你有没有拉国家的后腿?
- 根据广播星历计算GNSS卫星在瞬时地球坐标系中的坐标
- 目前常用计算机配置,电脑常见主要配置、参数
- 关键词搜索-关键词搜索引擎工具-关键词搜索排行榜
- 哔哩哔哩20校招算法笔试题(2019.8.20)第二道编程题 AC
- html和css最全的知识点归纳总结,html和css的面试知识点总结(附示例)
- 软件配置 | pip下载第三方库文件及配置pip源的不完全总结
- Arduino Pulsesensor脉搏心率的检测