本帖最后由 hj170520 于 2020-5-11 16:29 编辑
书接上文,https://www.52pojie.cn/thread-1171669-1-1.html
原始话题:https://www.52pojie.cn/thread-1171440-1-1.html
班上经常有粗心的同学,不老实签到,一直被班委提醒,现在我在原来的基础上增添了用csv包完成全班的自动签到,再也不担心没签到成功了!
[Python] 纯文本查看 复制代码 import csv
import json
import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15'
}
url_MD5 = "********************"
url_info = "********************"
url_submit = '********************t'
csvFile = open("cardId.csv", "r")
rows = csv.DictReader(csvFile)
cardId = []
for row in rows:
cardId.append(row["cardId"])
for i in range (len(cardId)):
cardId_x = cardId[i]
my_data = {"cardId": cardId_x}
res_MD5 = requests.post(url_MD5, headers = headers, data = my_data).text
res_MD_dict = json.loads(res_MD5)
MD5 = res_MD_dict["data"]
my_data["md5"] = MD5
res_info = requests.post(url_info, headers = headers, data = my_data).text
res_info_dict = json.loads(res_info)
list = res_info_dict["data"]["list"]
list_dict = dict(list[0])
data_submit = {}
data_submit["bh"] = list_dict["bh"]
data_submit["xykh"] = list_dict["xykh"]
data_submit["twfw"] = list_dict["twfw"]
data_submit["sfzx"] = list_dict["sfzx"]
data_submit["sfgl"] = list_dict["sfgl"]
data_submit["szsf"] = list_dict["szsf"]
data_submit["szds"] = list_dict["szds"]
data_submit["szxq"] = list_dict["szxq"]
data_submit["sfcg"] = list_dict["sfcg"]
data_submit["bllb"] = list_dict["bllb"]
data_submit["sfjctr"] = list_dict["sfjctr"]
data_submit["zcwd"] = list_dict["zcwd"]
data_submit["zwwd"] = list_dict["zwwd"]
data_submit["wswd"] = list_dict["wswd"]
data_submit["sbr"] = list_dict["sbr"]
data_submit["sjd"] = res_info_dict["data"]["sjd"]
print("可爱的'" + list_dict["xm"] + "'同学正在签到")
res_submit = requests.post(url_submit, headers=headers, data=data_submit).text
if json.loads(res_submit)["message"] == "成功":
print("签到成功")
else:
print("签到失败")
有朋友说“动态参数”,我还是新手,不太理解也就没有改。但是[Python] 纯文本查看 复制代码 requests.post(url_MD5, headers = headers, data = my_data).text
这个部分我改了,!我接下来想做爬虫了,有个etree函数没搞明白,希望更多的大佬能指点指点我
一会“赶火车”回学校了,我会想你们的。 |