模拟登录音乐网站自动签到
最近,发现了一个宝藏音乐网站,可以下载歌曲,又可以白嫖杰伦的歌曲了,但是呢,下载需要金币,要么花钱,要么就是每天签到,能白嫖怎么会花钱了,所以就写了这么一个模拟登录然后签到的脚本,每天定时签到。
首先,浏览器登录网站,获取cookie,不知道怎么获取cookie的话那就百度吧。
然后就是找签到接口,不知道的话也百度吧。
然后呢就看代码吧
方法一:urllib
# -*- coding:utf-8 -*-
# author:凌陨心
# datetime:2023/3/30 17:12
# software: PyCharm
import urllib.request
import urllib.parse
url = 'https://www.hifini.com/sg_sign.htm'
# 请求头参数
headers = {
'cookie': 'xxxx',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.54'
}
data = {'postdata': ''}
request = urllib.request.Request(url=url, headers=headers, method='POST', data=b'')
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
with open('hifi4.html', 'w', encoding='utf-8') as file:
file.write(content)
方法二:requests
# -*- coding:utf-8 -*-
# author:凌陨心
# datetime:2023/3/30 17:12
# software: PyCharm
import requests
url = 'https://www.hifini.com/sg_sign.htm'
# 请求头参数
headers = {
'cookie': 'xxx',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.54'
}
data = {'postdata': ''}
res = requests.post(url,data=b'',headers=headers)
print(res.text)
设置定时任务
ok
然后就是上传到服务器,并使用cron设置定时任务(cron一般是默认安装的,没装的话自己百度装一下),每天凌晨0点定时签到,very good
vi /etc/crontab
# 在最后追加:
0 0 * * * root python /opt/lihai/auto_login/login_hifi_with_cookie_1.py > /opt/lihai/auto_login/hifi.log 2>&1 &
# 然后重启服务
service cron restart
cron 服务的相关命令如下:
1)service cron start /*启动服务*/
2)service cron stop /*关闭服务*/
3)service cron restart /*重启服务*/
4)service cron reload /*重新载入配置*/
5)service cron status /*查看crond状态*/
over