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:[email protected]
'''
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' : '[email protected]', '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)
编程 xiami python python3.x postData 音乐 自动 252F 网页爬虫 签到 login 虾米 脚本 amp 网络爬虫
Answers
直接请求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
的问题,那个值不是固定的,所以你直接传递过去的话应该会有问题。