求python签到自动实现方法,虾米音乐签到
初学python以及编程,尝试写这样一个脚本,待成功后才会继续完善。
现在想要实现登陆。
问题:
- 请问我这个代码哪儿出了问题?登陆不成功。
-
headers和postData要写哪些出来,我用HttpFox抓包的。postData有perfect和raw版本,我在写的时候用哪个?
感谢!
header有如下几项:
(Request-Line) POST /member/login?callback=jQuery191069041835273338_1398059175342 HTTP/1.1
Host login.xiami.com
User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0
Accept text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01
Accept-Language zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip, deflate
Content-Type application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With XMLHttpRequest
Referer https://login.xiami.com/member/login?spm=a1z1s.6843761.226669510.8.mgS3ty
Content-Length 174
Cookie __utma=251084815.807798752.1397902515.1398051611.1398059164.8; __utmz=251084815.1397902515.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _xiamitoken=5d6acda6813fcfb509c692f961c1db91; _unsign_token=adb241a1ca1e9d88841a8b03f1dfbf0a; CNZZDATA921634=cnzz_eid%3D290074860-1397902517-null%26ntime%3D1398059175%26cnzz_a%3D16%26sin%3Dhttp%253A%252F%252Fwww.xiami.com%252F%26ltime%3D1398044904939%26rtime%3D1; CNZZDATA2629111=cnzz_eid%3D953933079-1397902517-null%26ntime%3D1398059175%26cnzz_a%3D16%26sin%3Dhttp%253A%252F%252Fwww.xiami.com%252F%26ltime%3D1398044905317%26rtime%3D1; __gads=ID=4810f3a98f707097:T=1397902585:S=ALNI_MZIeFDBRyd7UMnR4vzSVgiPocjL1Q; __utmb=251084815.3.10.1398059164; __utmc=251084815; t_sign_auth=3
Connection keep-alive
Pragma no-cache
Cache-Control no-cache
而postData有如下几项:
_xiamitoken 5d6acda6813fcfb509c692f961c1db91
done http%3A%2F%2Fwww.xiami.com
from web
havanaId
email 被我隐去(原始状态)
password 被我隐去(原始状态)
submit ç» å½
postData的raw版本:
_xiamitoken=5d6acda6813fcfb509c692f961c1db91&done=http%253A%252F%252Fwww.xiami.com&from=web&havanaId=&email=810233438%40qq.com&password=密码隐去(原始状态)&submit=%E7%99%BB+%E5%BD%95
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
'''
A simple py used to signin xiami
@author:caosz11@mails.tsinghua.edu.cn
'''
import urllib
from urllib import parse
from urllib import request
headers = {'User-Agent' : 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0', 'Referer' : 'https://login.xiami.com/member/login?spm=a1z1s.6843761.226669510.8.mgS3ty'}
postData = {'email' : 'XXX@qq.com', 'password' : 'XXX', 'done' : 'http%253A%252F%252Fwww.xiami.com', 'submit' : 'E7%99%BB+%E5%BD%95', '_xiamitoken' : '5d6acda6813fcfb509c692f961c1db91'}
postData = urllib.parse.urlencode(postData)
postData = postData.encode('utf-8')
print('Logging...')
req = urllib.request.Request('http://xiami.com/member/login', postData, headers)
result =urllib.request.urlopen(req).read()
result = result.decode('utf-8')
print(result)
感谢大家的帮助。
我写了一个简要的版本。
https://github.com/caosz11/xiami_signin
照抄抓包结果是不行的,比如你登陆发的请求中的_xiamitoken
,这个肯定不是固定的。
应该先去请求下Login页面,找到 _xiamitoken
,然后再拼POST请求。不要直接照抄,凡是看起来可疑的参数,多数是验证用的。
还有你Refer中的login url spm=a1z1s.6843761.226669510.8.mgS3ty
这一堆很可疑啊
直接请求Web页面的话可以参考这个代码(不确定新版页面是否可用):
http://www.luojs.com/2011/03/01/xiami_auto_signin/
但是你会发现其实模拟手机页面要简单很多,可以参考这个代码(目前也应该是可用的):
https://github.com/huxuan/xiami_auto_checkin/blob/master/xiami_auto_checkin.py
至于你代码有什么问题,我觉得应该是那个_xiamitoken
的问题,那个值不是固定的,所以你直接传递过去的话应该会有问题。
玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd19730.html
相关文章 Recommend
- • 2019年3月最新消息: Python 3.4.10 现已推出
- • [上海]招Python量化系统开发工程师
- • 优集品网络科技有限公司招Python中/高级工程师
- • 爱因互动科技发展有限公司招募Python开发攻城狮
- • mozio招聘Python/Django工程师
- • Kavout金融科技公司招Python研发工程师
- • Python数组逆向输出,编程练习题实例四十
- • Python数组插入排序,编程练习题实例三十九
- • Python矩阵for循环应用,编程练习题实例三十八
- • Python操作Redis数据库方面的问题
- • 请python高手帮我看看这段python代码中函数setter的
- • Python什么方法可以快速将两个队列变成字典
必知PYTHON教程 Must Know PYTHON Tutorials
- • python 解释器
- • python idle
- • python dir函数
- • python 数据类型
- • python type函数
- • python 字符串
- • python 整型数字
- • python 列表
- • python 元组
- • python 字典
- • python 集合
- • python 变量
- • python print
- • python 函数
- • python 类定义
- • python import
- • python help
- • python open
- • python 异常处理
- • python 注释
- • python continue
- • python pass
- • python return
- • python global
- • python assert
- • python if语句
- • python break
- • python for循环
- • python while循环
- • python else/elif
- • lambda匿名函数
必知PYTHON模块 Must Know PYTHON Modules
- • os 模块
- • sys 模块
- • re 正则表达式
- • time 日期时间
- • pickle 持久化
- • random 随机
- • csv 模块
- • logging 日志
- • socket网络通信
- • json模块
- • urlparse 解析URL
- • urllib 模块
- • urllib2 模块
- • robotparser 解析
- • Cookie 模块
- • smtplib 邮件
- • Base64 编码
- • xmlrpclib客户端
- • string 文本
- • Queue 线程安全
- • math数学计算
- • linecache缓存
- • threading多线程
- • sqlite3数据库
- • gzip压缩解压
最新内容 NEWS
- • Python程序员解决棘手问题的常用库
- • 求助关于restfull api接口几个问题
- • qiniu pythonsdk提示ImportError错误求解
- • 问一个关于Hadoop Python中读写文件统计分析
- • 求问str()同__str__原理上有什么不同,分别在
- • 大神帮忙看下20行的python代码,文件io和数
- • python 爬虫爬wiki 报错 [Errno 65] No route to
- • python续点上传问题None bad token...
- • python3环境下文本中超链接出错,要如何修
- • Python环境保存操作思路问题求助
图文精华 RECOMMEND
-
Python程序员解决棘手问题的常用库
-
求问str()同__str__原理上有什么不同
-
scrapy框架里面用link extractor怎么能
-
python {}.fromkeys创建字典append添加操
-
python3 类型Type str doesn't support th
-
python里面为什么系统的时区是东八
热点文章 HOT
- 学习Python有什么好的书籍推荐?
- Python匿名函数 Lambda表达式作用
- Python与Java、C、Ruby、PHP等编程语言有什么
- Python 正则中文网页字符串提取问题
- 如何为实时性应用存取经纬度?django my
- 想用python做个客户端,在二维码登录这个地
- 有让IDE可识别Python函数参数类型的方法吗
- Python字符串转换成列表正则疑问