投给猫饼的票,哈哈。一个acfun登陆+投票的代码
import requests
def vote(cookies):
"""投票"""
headers = {
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Connection': 'keep-alive',
'Content-Length': '44',
'Content-Type': 'application/json;charset=UTF-8',
'Host': 'activity.acfun.cn',
'Origin': 'http://activity.acfun.cn',
'Referer': 'http://activity.acfun.cn/m/acflower/detail/7443?shareId=745',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36'
}
url = 'http://activity.acfun.cn/api/vote/ballot'
payload = {
# 不确定哪一个元素是猫饼的
'itemId': '7443',
'voteGroupId': "",
'voteId': '70'
}
res = requests.post(url, headers=headers, json=payload, cookies=cookies)
print(res.json())
def login(username, password):
"""登录"""
url = 'https://id.app.acfun.cn/rest/web/login/signin'
headers = {
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Connection': 'keep-alive',
'Content-Length': '51',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Host': 'id.app.acfun.cn', 'Origin': 'http://www.acfun.cn', 'Referer': 'http://www.acfun.cn/login/?returnUrl=http%3A%2F%2Fwww.acfun.cn%2F',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36'
}
data = {
'username': username,
'password': password,
'key': '',
'captcha': ''
}
res = requests.post(url, headers=headers, data=data)
if res.status_code == 200:
cookies = res.cookies.get_dict()
print(cookies)
return cookies
else:
print('登录失败')
if __name__ == '__main__':
cookie = login('username', 'password')
vote(cookie)