python实现虾米音乐自动签到脚本

初学python以及编程,尝试写这样一个脚本,待成功后才会继续完善。
现在想要实现登陆。
问题:
请问我这个代码哪儿出了问题?登陆不成功。
headers和postData要写哪些出来,我用HttpFox抓包的。postData有perfect和raw版本,我在写的时候用哪个?
感谢!
header有如下几项:
(Request-Line)POST/member/login?callback=jQuery191069041835273338_1398059175342HTTP/1.1
Hostlogin.xiami.com
User-AgentMozilla/5.0(X11;Ubuntu;Linuxx86_64;rv:28.0)Gecko/20100101Firefox/28.0
Accepttext/javascript,application/javascript,application/ecmascript,application/x-ecmascript,*/*;q=0.01
Accept-Languagezh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encodinggzip,deflate
Content-Typeapplication/x-www-form-urlencoded;charset=UTF-8
X-Requested-WithXMLHttpRequest
Refererhttps://login.xiami.com/member/login?spm=a1z1s.6843761.226669510.8.mgS3ty
Content-Length174
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
Connectionkeep-alive
Pragmano-cache
Cache-Controlno-cache
而postData有如下几项:
_xiamitoken5d6acda6813fcfb509c692f961c1db91
donehttp%3A%2F%2Fwww.xiami.com
fromweb
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/envpython3
#-*-coding:utf-8-*-
'''
Asimplepyusedtosigninxiami
@author:caosz11@mails.tsinghua.edu.cn
'''
importurllib
fromurllibimportparse
fromurllibimportrequest
headers={'User-Agent':'Mozilla/5.0(X11;Ubuntu;Linuxx86_64;rv:28.0)Gecko/20100101Firefox/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)
慕尼黑8549860
浏览 633回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript