本次以csdn自动签到脚本为例,代码如下,详细请了解这篇文章:https://blog.csdn.net/weixin_44146025/article/details/113248878?spm=1001.2014.3001.5501
import requests
import time
import json
headers = {
'accept':'application/json, text/plain, */*',
'accept-encoding':'gzip, deflate, br',
'accept-language':'zh-CN,zh;q=0.9',
'cache-control':'no-cache',
'content-length':'247',
'content-type':'application/json;charset=UTF-8',
'cookie':'uuid_tt_dd=10_21002145320-1569306368647-530289; Hm_ct_6bcd52f51e9b3dce32bec4a3997715ac=6525*1*10_21002145320-1569306368647-530289!5744*1*weixin_44146025; smidV2=20191005152519e1672eec8bb7335ddb17a4136f900bdb0026dd2b7087b3920; __gads=ID=0685ee9dbd699171:T=1586574128:S=ALNI_Ma-iLaOhW5baScFk231_hCbGvQ6ig; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1603427841,1604050694,1604221011; UN=weixin_44146025; p_uid=U010000; UserName=weixin_44146025; UserInfo=c73862634fbd43898c7a21a8056f5875; UserToken=c73862634fbd43898c7a21a8056f5875; UserNick=%E5%86%89%E7%AD%B1; AU=F33; BT=1611574167593; c_first_ref=default; c_first_page=https%3A//blog.csdn.net/weixin_44146025; c_segment=1; dc_sid=0e80cf352440f868d25db0d6f1bdc277; is_advert=1; c_page_id=default; c_ref=https%3A//blog.csdn.net/weixin_44146025; dc_session_id=10_1611727790454.373035; dc_tos=qnkx4f; log_Id_pv=905; log_Id_click=583',
'pragma':'no-cache',
'referer':'https://i.csdn.net/',
'sec-fetch-dest':'empty',
'sec-fetch-mode':'cors',
'sec-fetch-site':'same-site',
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
}
data = {
'ip':'',
'platform':'pc-my',
'product':'pc',
'user_agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
'username':'weixin_44146025',
'uuid':'10_21002145320-1569306368647-530289'
}
r = requests.post("https://me.csdn.net/api/LuckyDraw_v2/signIn",headers=headers,data=data)
now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
msg = r.json()
try:
with open('wenjian.txt', 'a') as f:
f.write('{} --- {}\n'.format(now, msg))
f.close()
print(msg)
except Exception as e:
print(e)
首先 查看当前定时任务:
crontab /etc/crontab
crontab -l
然后咱们的目标是:每天 上午9:00 签到
分钟 小时 日期 月份 周几 用户名 命令
0 9 * * * root /usr/bin/python2.7 /home/qiandao/qiandao.py
但是这样有点麻烦,就整了一个shell脚本,也是要上传的,脚步内容为:
#!/bin/bash
/usr/bin/python2.7 /home/csdnqd/csdnqd.py
然后重新启动crontab程序:
systemctl restart crond.service
应该还没成功,因为要把test.sh文件设置为可执行文件。代码如下:
chmod +777 test.sh
Linux命令 ls 查看当前文件夹的文件,颜色变了就好了
再重启一下程序,应该就没问题了。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/114766.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...