环境:
Windows 10Python 3.7
说明:
关于登录问题:
username
= '123456789'
UserPwd
= '********'
本地cookie文件 运行后会生成cookie_index.txt与cookie_login.txt文件,里面存放着登录需要的cookie信息。
签到: 复制字符串到https://www.bejson.com/enc/urlencode/解码并修改相应的中文再编码
qiang_data
= 'InternStateId=4&interContent=文本内容&logImg=&posAddress=地址&posLong=经纬度&posLati=经纬度&locationType=1&ArticleId=0'
代码
'''
闯越顶岗实习签到程序
'''
import requests
import sys
import json
import win32api
import win32con
import os
import _thread
import datetime
cookie_login
= {}
cookie_index
= {}
def get_login():
global cookie_login
global cookie_index
login_headers
= {
'Host': 'hl.cydgsx.com',
'Connection': 'keep-alive',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'https://hl.cydgsx.com',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://hl.cydgsx.com/m/Home/Index',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7'
}
username
= '123456789'
UserPwd
= '********'
login_data
= 'username={}&UserPwd={}&wxInfo=&openid='.format(
username
, UserPwd
)
login
= requests
.post
(
'https://hl.cydgsx.com/m/Home/CheckLoginJson', headers
=login_headers
, data
=login_data
)
cookie_login
= requests
.utils
.dict_from_cookiejar
(login
.cookies
)
index_headers
= {
'Host': 'hl.cydgsx.com',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-User': '?1',
'Sec-Fetch-Dest': 'document',
'Referer': 'https://hl.cydgsx.com/m/Home/Index',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7',
'Cookie': 'LoginUser_Id={0}; loginUserName={1}'.format(cookie_login
['LoginUser_Id'], cookie_login
['loginUserName'])
}
get_index
= requests
.get
(
'https://hl.cydgsx.com/m/s/Home/Index', headers
=index_headers
)
cookie_index
= requests
.utils
.dict_from_cookiejar
(get_index
.cookies
)
save_cookie
()
def save_cookie():
global cookie_index
global cookie_login
file_path
= os
.path
.dirname
(__file__
)
with open('{}\cookie_index.txt'.format(file_path
), "w") as index
:
json
.dump
(cookie_index
, index
)
with open("{}\cookie_login.txt".format(file_path
), "w") as login
:
json
.dump
(cookie_login
, login
)
def open_cookie():
global cookie_index
global cookie_login
try:
with open("cookie_index.txt", "r") as index
:
cookie_index
= json
.load
(index
)
with open("cookie_login.txt", "r") as login
:
cookie_login
= json
.load
(login
)
except:
get_login
()
def get_datetime():
now
= datetime
.datetime
.now
().date
()
year
, month
, day
= str(now
).split
("-")
year
= int(year
)
month
= int(month
)
day
= int(day
)
weekday
= datetime
.datetime
.now
().weekday
()
if weekday
== 6:
try:
_thread
.start_new_thread
(zhou_qiandao
, (now
,))
except:
print('无法启动周签到线程')
def last_day(any_day
):
next_month
= any_day
.replace
(day
=28) + datetime
.timedelta
(days
=4)
return next_month
- datetime
.timedelta
(days
=next_month
.day
)
last_day
= last_day
(datetime
.date
(year
, month
, day
))
if now
== last_day
:
yue_qiandao
(now
)
def qiandao():
headers
= {
'Host': 'hl.cydgsx.com',
'Connection': 'keep-alive',
'Content-Length': '292',
'Accept': '*/*',
'Origin': 'https://hl.cydgsx.com',
'X-Requested-With': 'XMLHttpRequest',
'Sec-Fetch-Dest': 'empty',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Referer': 'https://hl.cydgsx.com/m/s/Log/wLog',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cookie': 'ASP.NET_SessionId={0}; jxnApp=0; giveCard_10269={1}; loginUserName={2}; LoginTimeCooikeName=8ee100zxcdb2c3afd71eax4501ec36b1; LoginUser_Id={3}'.format(cookie_index
['ASP.NET_SessionId'], cookie_index
['giveCard_10269'], cookie_login
['loginUserName'], cookie_login
['LoginUser_Id'])
}
qiang_data
= 'InternStateId=4&interContent=文本内容&logImg=&posAddress=地址&posLong=经纬度&posLati=经纬度&locationType=1&ArticleId=0'
get_qian
= requests
.post
(
'https://hl.cydgsx.com/m/s/Log/SaveWriteLog', headers
=headers
, data
=qiang_data
)
if get_qian
.text
.find
('请重新登录') != -1:
get_login
()
qiandao
()
get_json
= json
.loads
(get_qian
.text
)
try:
if get_json
['state'] == 1:
print('已签到')
else:
print('重复签到')
print(get_json
['meg'])
except KeyError
as e
:
print(e
)
print('尝试重新运行')
def zhou_qiandao(today
):
headers
= {
'Host': 'hl.cydgsx.com',
'Connection': 'keep-alive',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Origin': 'https://hl.cydgsx.com',
'X-Requested-With': 'XMLHttpRequest',
'Sec-Fetch-Dest': 'empty',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Referer': 'https://hl.cydgsx.com/m/s/Log/wWeekSmy?date={}'.format(today
),
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cookie': 'ASP.NET_SessionId={0}; jxnApp=0; giveCard_10269={1}; loginUserName={2}; LoginTimeCooikeName=8ee100zxcdb2c3afd71eax4501ec36b1; LoginUser_Id={3}'.format(cookie_index
['ASP.NET_SessionId'], cookie_index
['giveCard_10269'], cookie_login
['loginUserName'], cookie_login
['LoginUser_Id'])
}
zhou_data
= 'logImg=&smyDate={}&summaryType=周小结&summaryInfo=累'.format(
today
)
zhou
= requests
.post
(
'https://hl.cydgsx.com/m/s/Log/SaveSmyJson', headers
=headers
, data
=zhou_data
)
zhou_json
= json
.loads
(zhou
.text
)
try:
if zhou_json
['state'] == 1:
print('已填写周记')
else:
print('重复填写周记:{}'.format(zhou_json
['meg']))
except KeyError
as e
:
print(e
)
print('尝试重新运行')
def yue_qiandao(today
):
headers
= {
'Host': 'hl.cydgsx.com',
'Connection': 'keep-alive',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Origin': 'https://hl.cydgsx.com',
'X-Requested-With': 'XMLHttpRequest',
'Sec-Fetch-Dest': 'empty',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Referer': 'https://hl.cydgsx.com/m/s/Log/wMonthSmy?date={}'.format(today
),
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cookie': 'ASP.NET_SessionId={0}; jxnApp=0; giveCard_10269={1}; loginUserName={2}; LoginTimeCooikeName=8ee100zxcdb2c3afd71eax4501ec36b1; LoginUser_Id={3}'.format(cookie_index
['ASP.NET_SessionId'], cookie_index
['giveCard_10269'], cookie_login
['loginUserName'], cookie_login
['LoginUser_Id'])
}
yue_data
= 'logImg=&smyDate={}&summaryType=月小结&summaryInfo=还不错'.format(
today
)
yue
= requests
.post
(
'https://hl.cydgsx.com/m/s/Log/SaveSmyJson', headers
=headers
, data
=yue_data
)
yue_json
= json
.loads
(yue
.text
)
try:
if yue_json
['state'] == 1:
print('已填写月记')
else:
print('重复填写月记:{}'.format(yue_json
['meg']))
except KeyError
as e
:
print(e
)
print('尝试重新运行')
def get_keyvalue(key
):
try:
i
= 0
while True:
yield win32api
.RegEnumValue
(key
, i
)
i
+= 1
except Exception
as e
:
pass
finally:
key
.close
()
def open_win():
file_name
= os
.path
.basename
(__file__
)
file_path
= os
.path
.splitext
(file_name
)[0]
file_exe
= str(os
.path
.dirname
('./'))+'\\'+file_path
path
= os
.path
.abspath
(file_exe
)
print(path
)
KeyName
= 'Software\\Microsoft\\Windows\\CurrentVersion\\Run'
keyHandle
= win32api
.RegConnectRegistry
(None, win32con
.HKEY_CURRENT_USER
)
key
= win32api
.RegOpenKeyEx
(keyHandle
, KeyName
, 0, win32con
.KEY_ALL_ACCESS
)
reg_data
= list(get_keyvalue
(key
))
for i
in range(len(reg_data
)):
if reg_data
[i
][0] == 'cydgsx':
print('已添加为自启动。。。')
return True
else:
pass
print('添加为自启动。。。')
try:
key
= win32api
.RegOpenKey
(
keyHandle
, KeyName
, 0, win32con
.KEY_ALL_ACCESS
)
win32api
.RegSetValueEx
(key
, file_path
, 0, win32con
.REG_SZ
, path
)
win32api
.RegCloseKey
(key
)
except Exception
as e
:
print('添加失败')
print(e
)
return False
print('添加成功')
if __name__
== "__main__":
open_cookie
()
try:
_thread
.start_new_thread
(open_win
, ())
_thread
.start_new_thread
(get_datetime
, ())
except Exception
as e
:
print('无法启动线程')
print(e
)
qiandao
()
os
.system
('pause')
成品: