还在为每天忘记签到而烦恼吗?python来帮你搞定! [ 2.0 版本 ]
1、安装环境
首先看一下服务器是否安装Python
$ python -V
$ Python 2.7.5
2、使用脚本安装和升级pip
$ wget https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py
$ pip -V #查看pip版本
3、直接上代码
# coding=utf-8
import re
import requests
# 登录地址
url = "https://www.yiichina.com/login"
# 签到地址
url2 = "https://www.yiichina.com/registration"
# 构造登陆的header头
headers = {
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
'Accept-Encoding': "gzip, deflate, br",
'Accept-Language': "zh-CN,zh;q=0.9,en;q=0.8",
'Cache-Control': "no-cache",
'Connection': "keep-alive",
'Content-Length': "250",
'Content-Type': "application/x-www-form-urlencoded",
'Host': "www.yiichina.com",
'Origin': "https://www.yiichina.com",
'Pragma': "no-cache",
'Referer': "https://www.yiichina.com/login",
'Upgrade-Insecure-Requests': "1",
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/67.0.3396.99 Safari/537.36 "
}
# 构造签到的header头
headers2 = {
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
'Accept-Encoding': "gzip, deflate, br",
'Accept-Language': "zh-CN,zh;q=0.9,en;q=0.8",
'Cache-Control': "no-cache",
'Connection': "keep-alive",
'Content-Length': "250",
'Content-Type': "application/x-www-form-urlencoded",
'Host': "www.yiichina.com",
'Origin': "https://www.yiichina.com",
'Pragma': "no-cache",
'Referer': "https://www.yiichina.com/",
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/67.0.3396.99 Safari/537.36",
'X-CSRF-Token': "jiZGgvngdp0HiiclI4SheJlJr5-lVyymIFgbfE1ZUw33FWv2mI5DzyrJFUFHt8tO_h3az84GH9xEHEtFCh8cfg==",
'X-Requested-With': "XMLHttpRequest"
}
# 登陆方法和签到
def login_sign():
r_session = requests.Session()
page = r_session.get(url)
reg = r'<meta name="csrf-token" content="(.+)">'
csrf = re.findall(reg, page.content)[0]
data = {
"_csrf": csrf,
"LoginForm[username]": "******",
"LoginForm[password]": "******",
'LoginForm[rememberMe]': "0",
"LoginForm[rememberMe]": "1",
"login - button": ""
}
# 完成用户登录
response1 = r_session.post(url, data=data, headers=headers)
print(response1.content) #这里可以看到是否模拟登陆成功
page2 = r_session.get(url2)
reg = r'<meta name="csrf-token" content="(.+)">'
csrf = re.findall(reg, page2.content)[0]
data2 = {
"_csrf": csrf
}
# 模拟签到请求
response2 = r_session.post(url2, data=data2, headers=headers2)
print(response2.content)
if __name__ == "__main__":
login_sign()
header头里面的内容可以直接从浏览器复制过来
4、安装requests模块
$ pip install requests
5、在linux通过定时任务执行
$ crontab -e
更具自己的需要设置定时任务
# 自动签到
30 11 * * * python /root/sign.py # /root/sign.py表示对应的文件路径
这里注意要给文件增加一个写的权限
$ chmod +x sign.py
6、纯粹个人简介,有问题请留言
zavier
注册时间:2016-04-01
最后登录:2024-07-09
在线时长:5344小时55分
最后登录:2024-07-09
在线时长:5344小时55分
- 粉丝19
- 金钱10895
- 威望30
- 积分64635
共 3 条评论
来个php的
https://github.com/crazePhper/yii2Sign
@小叮当的肚兜 你为啥这么优秀
@小叮当的肚兜 执行报错请求登录页面->Error: 60: Peer certificate cannot be authenticated with given CA certificates: SSL certificate problem: unable to get local issuer certificate
@稍息!立正〜★论 好像我以前遇到过这个问题,去网上查查能解决。
https://blog.csdn.net/buer2202/article/details/75364589
哈哈,棒棒哒签到。萌新第二天打卡
运行报错。。。。