一、前言
- 功能:获取微信投票所有选手的信息,绘制成表格。
- 需要手动操作:因为需要微信登录,所以每十几分钟需要手动换一下token
二、代码
import requests
import json
from xlwt import *
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0",
"token": "tWHfLl3/7mCadgpZYPoSDQ=="
}
id_list = []
for page in range(1, 7):
url = "https://vote.tyzyz.com.cn/api/vote/get_vote_list.json"
data = {
"code_and_name": "",
"recommend_type": 0,
"pageno": page,
"pagesize": 10,
"area": ""
}
page_text = requests.post(url=url, headers=headers, data=data).text
rows = json.loads(page_text)["data"]["page_list"]["rows"]
for i in rows:
id_list.append(i["id"])
message_list = [
["项目名称", "排名", "票数", "执行团队", "项目类型", "项目来源", "项目起源"],
]
for id in id_list:
url = "https://vote.tyzyz.com.cn/api/vote/get_id_vote.json?id=" + str(id)
page_text = requests.get(url=url, headers=headers).text
rows = json.loads(page_text)["data"]
message = []
message.append(rows["name"])
message.append(rows["number"])
message.append(rows["votes"])
message.append(rows["orgname"])
message.append(rows["recommendType"])
message.append(rows["area"])
message.append(rows["briefDeeds"])
message_list.append(message)
file = Workbook(encoding='utf-8')
table = file.add_sheet('message')
for i in range(0, len(message_list)):
message_i = message_list[i]
for j in range(0, len(message_i)):
table.write(i + 1, j, message_i[j])
file.save('./message.xlsx')