python 利用requests 实现小米网登陆 的代码分享
来源:互联网 发布:oracle数据库迁移步骤 编辑:程序博客网 时间:2024/06/11 21:28
这是博主写出来记录下这个运用python 登陆网站的流程首先准备火狐浏览器和firebug插件,用这两个工具分析是什么方法提交数据登陆小米网的。1.浏览目标网站2.打开firebug3.登陆账号并分析数据包4。代码说明formdata 我们构造的要提交的数据 ,注意的是:request库中添加的数据会自动进行url编码。如http://www.xiao.com 提交的数据会变成http%3A%2F%2Fwww.xiaomi.com ,所以我们得让数据包的url地址进行反url编码,
就是http%3A%2F%2Fwww.xiaomi.com 换成http://www.xiao.com ,特性地,有时地址会进行二次url编码因为
%25 进行反url编码等于% ,所以%253A 其实等于%3A等于:
post表单,服务器返回的数据,location就是一个临时get方法登陆url,处理前面的start字符串,当成字典
提取出这个地址,再用requests的get方法就能登陆完成
#!user/bin/env python# -*- coding:utf-8 -*-import requests
formdata = { '_json': 'true', '_sign': '8SP7jyhVuil0sSM4PSn+ZSpJQ6g=',
'callback': 'http://order.mi.com/login/callback?followup=http%3A%2F%2Fwww.mi.com%2Findex.html&sign=NDRhYjQwYmNlZTg2ZGJhZjI0MTJjY2ZiMTNiZWExODMwYjkwNzg2ZQ,,',
'hash': '',#密码的hash值
'qs': '%3Fcallback%3Dhttp%253A%252F%252Forder.mi.com%252Flogin%252Fcallback%253Ffollowup%253Dhttp%25253A%25252F%25252Fwww.mi.com%25252Findex.html%2526sign%253DNDRhYjQwYmNlZTg2ZGJhZjI0MTJjY2ZiMTNiZWExODMwYjkwNzg2ZQ%252C%252C%26sid%3Dmi_eshop',
'serviceParam': '{"checkSafePhone":false}',
'sid': 'mi_eshop',
'user': ''#账号}
req_header = { 'Referer': 'https: // account.xiaomi.com',
'Host': 'account.xiaomi.com'}
text_url = 'https://account.xiaomi.com/pass/serviceLoginAuth2?_dc=1463973240172'
urls = 'https://account.xiaomi.com/pass/serviceLogin?callback=http%3A%2F%2Forder.mi.com%2Flogin%2Fcallback%3Ffollowup%3Dhttp%253A%252F%252Fwww.mi.com%252Findex.html%26sign%3DNDRhYjQwYmNlZTg2ZGJhZjI0MTJjY2ZiMTNiZWExODMwYjkwNzg2ZQ%2C%2C&sid=mi_eshop'
r = requests.get(urls)loginhtml = r.content
r = requests.post(text_url, data=formdata, headers=req_header)
_cookies = r.cookies
print r.status_code
location = r.content
location = location.replace("null", "0").replace("&&&START&&&", "")
print location
location_dict = eval(location)
index_url = location_dict['location']
r = requests.get(index_url, _cookies)
print r.url
print r.content
0 0
- python 利用requests 实现小米网登陆 的代码分享
- 使用Python的Requests包模拟登陆
- 利用Python requests库模拟登陆学校教务系统
- 利用python requests库模拟登陆知乎
- Python requests 模拟登陆
- 利用requests 模拟登陆csdn
- 五.python requests ip伪装,cookie登陆获取,利用cookie进行登陆
- python requests模拟登陆github
- 使用 python requests 模拟登陆
- python requests模拟登陆带验证码的网站
- 利用MOSS的SSO实现单点登陆[代码]-zt
- 利用Python的requests模块爬取当当网的书籍信息(待续)
- 【LeetCode】Python requests模拟Leetcode登陆
- Python模拟登陆(使用requests库)
- 利用Python实现基于Requests框架和多线程技术的Tumblr博客空间图片及视频下载
- 记录使用requests模块实现登陆csdn
- python的requests库
- python 的requests模块
- oracle 12C 故障解析
- centOs6.5 SVN 服务器搭建并实现提交自动同步到web服务器
- android LRUCache源码分析
- 堆栈里的迭代器
- iOS 8 Auto Layout界面自动布局系列2-使用Xcode的Interface Builder添加布局约束
- python 利用requests 实现小米网登陆 的代码分享
- fopen()函数模式字符串
- 编辑距离、拼写检查与度量空间:一个有趣的数据结构
- Hibernate与java、标准sql数据类型对应关系
- Android四种启动Activity方式
- 一图片持续360度旋转
- Linux——搭建Redis集群
- sizeof() 与 strlen()区别与联系
- android studio之gradle的更新