安装依赖、添加权限:
apt-get install -y python3-pip python3-requests python3-termcolor
chmod +x loc.py
创建loc.py文件,将以下文件都放在同目录下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#!/usr/bin/python3 #coding:utf-8 #import sys #print(sys.version) from datetime import * bjtime=str(datetime.utcnow().replace(tzinfo=timezone.utc).astimezone(timezone(timedelta(hours=8)))).split('.')[0] print('北京时间: ' + bjtime) import requests sess=requests.session() headers={ 'Host': 'www.hostloc.com', 'Connection': 'keep-alive', 'Cache-Control': 'max-age=0', 'Origin': 'https://www.hostloc.com', 'Upgrade-Insecure-Requests': '1', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Referer': 'https://www.hostloc.com/forum.php', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-HK,zh;q=0.9,zh-CN;q=0.8,en-US;q=0.7,en;q=0.6,zh-TW;q=0.5' } data={ 'fastloginfield':'username', 'username':'', 'password':'', 'cookietime':'2592000', 'quickforward':'yes', 'handlekey':'ls' } import sys data['username']=sys.argv[1] data['password']=sys.argv[2] sess.post('https://www.hostloc.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1',headers=headers,data=data) import random import re bscore=re.findall('积分: ([0-9]+)',sess.get('https://www.hostloc.com/forum.php').content.decode('utf-8'))[0] print('Hostloc签到前积分: ',bscore) # [ sess.get('http://www.hostloc.com/space-uid-{}.html'.format(random.randint(10000,20000))) for i in range(15) ] from multiprocessing.dummy import Pool as ThreadPool pool = ThreadPool(10) # 10个线程 results = pool.map(lambda x: sess.get(x), [ 'https://www.hostloc.com/space-uid-{}.html'.format(random.randint(10000,20000)) for i in range(20) ]) # urls是任务列表 list,第一个参数是线程函数 # close the pool and wait for the work to finish pool.close() pool.join() ascore=re.findall('积分: ([0-9]+)',sess.get('https://www.hostloc.com/forum.php').content.decode('utf-8'))[0] print('Hostloc签到后积分: ',ascore) from termcolor import * print(colored('签到成功!','green')) if (int(ascore)-int(bscore)>=20) else print(colored('签到失败!','red')) exit(0) if (int(ascore)-int(bscore)>=20) else exit(1) |
创建run.sh文件,将以下文件都放在同目录下:
1 2 3 4 5 6 |
#!/bin/bash export LANGUAGE=zh_CN.utf-8 echo $LANGUAGE echo 'loc 签到 user1' && ./loc.py 'user1' 'userpassword' # 用户名密码建议用引号包起来 # 继续添加 账号 echo 'loc 签到 user2' && ./loc.py 'user2' 'userpassword' # 用户名密码建议用引号包起来 |
添加自动任务:
1 2 3 |
crontab -e 0 */6 * * * cd /root && bash run.sh >> run.log 2>& |
注意用户名和密码要正确,不然会运行脚本会出错的。