Hostloc论坛自动签到Python脚本

说明

  • 支持金钱显示
  • 支持多用户
  • 支持无服务器函数
  • 更新时间间隔

开始

安装 Python3

apt-get install python3-pip

新建一个名为hostloc.py的文件,然后在文件中写入以下代码
将其中的账号A替换成自己的,密码A也替换成自己的即可,多账号自行添加,注意前面的数字编号;
注意:不要用电脑的TXT记事本编辑,避免格式出错,直接在宝塔面板编辑即可;

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Author:  MoeClub.org

import re
import sys
import time
from urllib import request, parse
from http import cookiejar


account_dict = {
    '0': {'username': '账号A', 'password': '密码A'},
    '1': {'username': '账户B', 'password': '密码B'},
}


def Login(URL, UserData):
    _cookies = ''
    _cookie = cookiejar.CookieJar()
    _handler = request.HTTPCookieProcessor(_cookie)
    _req = request.Request(URL, data=parse.urlencode(UserData).encode('utf-8'))
    request.build_opener(_handler).open(_req)
    for cookie in _cookie:
        _cookies += cookie.name + '=' + cookie.value + ';'
    return _cookies


def GetPage(URL, Header_Cookies):
    _Header = {'Cookie': str(Header_Cookies)}
    _req = request.Request(URL, headers=_Header)
    return request.urlopen(_req).read().decode('utf-8')


def GetCredit(user_data, proto='https'):
    username = user_data['username']
    Login_URL = proto + '://hostloc.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1'
    My_Credit = proto + '://hostloc.com/home.php?mod=spacecp&ac=credit&showcredit=1&inajax=1'
    My_Home = proto + '://hostloc.com/home.php?mod=spacecp&inajax=1'
    My_Cookies = Login(Login_URL, user_data)

    if '<td>' + str(username) + '</td>' not in GetPage(My_Home, My_Cookies):
        print('[%s] Login Fail!' % username)
    else:
        try:
            CreditNum0 = str(re.findall('[0-9]+', GetPage(My_Credit, My_Cookies))[-1])
        except:
            CreditNum0 = 'Null'
        for x in range(25297, 25309):
            GetPage(proto + '://hostloc.com/space-uid-{}.html'.format(x), My_Cookies)
            time.sleep(4)
        try:
            if CreditNum0 == 'Null':
                raise Exception
            CreditNum1 = str(re.findall('[0-9]+', GetPage(My_Credit, My_Cookies))[-1])
            if CreditNum0 == CreditNum1:
                CreditDetails = str(CreditNum1)
            else:
                CreditDetails = str(CreditNum0) + '->' + str(CreditNum1)
        except:
            CreditDetails = 'Null'
        print('[%s] Login Success! (Credit: %s)' % (username, CreditDetails))


if __name__ == '__main__':
    if len(sys.argv) > 1:
        n = 0
        account_dict = {}
        account_list = [sys.argv[x] for x in range(1, len(sys.argv))]
        for account in account_list:
            if ":" not in account:
                continue
            account_dict[str(n)] = {}
            account_dict[str(n)]['username'] = str(str(account).split(":", 1)[0])
            account_dict[str(n)]['password'] = str(str(account).split(":", 1)[-1])
            n += 1
    for i in range(0, len(account_dict)):
        try:
            GetCredit(account_dict[str(i)])
            time.sleep(4)
        except:
            continue

创建自动执行签到任务

在宝塔面板自动任务创建一个Shell脚本自动计划任务
脚本内容:

# 进入hostloc.py文件所在目录的绝对路径
cd /home/Loc
# 执行签到任务
python3 ./hostloc.py

示例:
图片[1]-Hostloc论坛自动签到Python脚本-安全小百科
创建完成后点击执行,等待执行完成后查看日志,如果没有问题就可以了
提示:尽量将自动签到时间设定到半夜,白天论坛的CC防御规则严格,会使签到失败,设置在半夜就没问题了;
博主的签到日志:

----------------------------------------------------------------------------
★[2019-11-22 01:10:51] Successful
----------------------------------------------------------------------------
[xxx] Login Success! (Credit: 10669->10689)
[xxx] Login Success! (Credit: 2643->2663)
[xxx] Login Success! (Credit: 1105->1125)
----------------------------------------------------------------------------
★[2019-11-23 01:10:49] Successful
----------------------------------------------------------------------------
[xxx] Login Success! (Credit: 10692->10712)
[xxx] Login Success! (Credit: 2665->2685)
[xxx] Login Success! (Credit: 1127->1147)
----------------------------------------------------------------------------
★[2019-11-24 01:10:49] Successful
----------------------------------------------------------------------------
[xxx] Login Success! (Credit: 10722->10742)
[xxx] Login Success! (Credit: 2687->2707)
[xxx] Login Success! (Credit: 1149->1169)
----------------------------------------------------------------------------

相关推荐: Linux下用wget下载Google drive上的大文件|直链|绕过病毒扫描警告|安全查杀|直连

文章目录[隐藏] 前言 小文件获取直链 大文件跳过病毒扫描警告 前言 Google Drive是个好东西,无限容量+无限分享。 但是下载的时候问题来了,有时候我们只需要下载到服务器中即可,但是如何获取直链呢? 小文件获取直链 如果一个文件的地址是https:/…

© 版权声明
THE END
喜欢就支持一下吧
点赞0
分享
评论 抢沙发

请登录后发表评论