python sina 围脖登陆
2013-03-17 20:32
225 查看
importre importjson importurllib importbase64 importhashlib importrequests WBCLIENT='ssologin.js(v.1.3.18)' sha1=lambdax:hashlib.sha1(x).hexdigest() defwblogin(username,password): session=requests.Session() #headers={ #'User-Agent':'Mozilla/5.0(WindowsNT5.1)AppleWebKit/537.1(KHT' #'ML,likeGecko)Chrome/21.0.1180.89Safari/537.1' #} #) resp=session.get( 'http://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sina' 'SSOController.preloginCallBack&su=%s&client=%s'% (base64.b64encode(username),WBCLIENT) ) pre_login_str=re.match(r'[^{]+({.+?})',resp.content).group(1) pre_login_json=json.loads(pre_login_str) data={ 'entry':'weibo', 'gateway':1, 'from':'', 'savestate':7, 'useticket':1, 'ssosimplelogin':1, 'su':base64.b64encode(urllib.quote(username)), 'service':'miniblog', 'servertime':pre_login_json['servertime'], 'nonce':pre_login_json['nonce'], 'pcid':pre_login_json['pcid'], 'vsnf':1, 'vsnval':'', 'pwencode':'wsse', 'sp':sha1(sha1(sha1(password))+ str(pre_login_json['servertime'])+ pre_login_json['nonce']), 'encoding':'UTF-8', 'url':'http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.si' 'naSSOController.feedBackUrlCallBack', 'returntype':'META' } resp=session.post( 'http://login.sina.com.cn/sso/login.php?client=%s'%WBCLIENT, data=data ) login_url=re.search(r'replace\([\"\']([^\'\"]+)[\"\']', resp.content).group(1) resp=session.get(login_url) login_str=re.match(r'[^{]+({.+?}})',resp.content).group(1) returnsession,json.loads(login_str) if__name__=='__main__': frompprintimportpprint session,login_info=wblogin('xxxxxxx@qq.com','xxxxxx') uid=login_info['userinfo']['uniqueid'] url="http://weibo.com/u/"+uid resp=session.get(url) printresp.content
智普教育《python小弟编辑》:http://www.jeapedu.com/
相关文章推荐
- Python3网络爬虫(三):Python3使用Cookie-模拟登陆获取妹子联系方式
- python实例1:创建一个登陆模块
- python操作ie登陆土豆网的方法
- python登陆百度网盘并读取自己的所有文件,输出到文本文件中
- Python实现的使用telnet登陆聊天室实例
- Python:新浪微博API的使用及安全的模拟登陆自动获取code值
- python-38: 网页登陆流程
- Python post、get百度(登陆)
- python paramiko 通过密钥文件登陆ssh和听过sftp上传文件
- Python命令行注册pypi出现410报错无法登陆的问题解决
- python模拟登陆
- Python学习笔记_02:使用Tkinter连接MySQL数据库实现登陆注册功能
- 新浪sina.cn邮箱注册python版
- Python 爬虫模拟登陆知乎
- python爬虫之模拟登陆csdn的实例代码
- 瀚海星云BBS python脚本登陆
- Python实现SSH远程登陆,并执行远程命令
- 项目总结(三)----------Python实现SSH远程登陆,并执行命令!
- python 用户登陆
- python 模拟登陆并打开网页下载