Python 实现 Discuz 论坛自动登录踢楼

2,875次阅读

共计 1810 个字符,预计需要花费 5 分钟才能阅读完成。

# -*- coding: utf-8 -*
import requests
import time #不延时可以去掉
import re
import os
import sys
import string

n = 0 #循环次数
a = 9 #计数器
b = 0
tiloun = 88 #中奖楼层
tilouid = 8888 #踢楼帖子 ID
Read_nowlou = 0 #当前楼层
starttime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
nowtime = 0
msg="这里是"# 踢楼恢复内容

username = '论坛账户'  # 论坛账户
password = '论坛密码'  # 论坛密码

login_url = 'https://hostloc.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1'  # post 登录接口
request = requests.post(login_url, {"username": username, 'password': password})  # 登录一次,获取 request
cookie = request.cookies  # 获取 request 里的 cookie
user_info = requests.get('https://hostloc.com/thread-%s-1-1.html'%(tilouid), cookies=cookie).text  #
formhash = re.search(r'formhash=\S{8}', user_info).group(0)[9:]  # 积分中心使用 re 获取


while n < 1 :
#        if sys.platform=="win32":
#                os.system("cls")
#        elif sys.platform=="linux":
#                os.system("clear")
        try:
                user_info = requests.get('https://hostloc.com/thread-%s-1-1.html'%(tilouid), cookies=cookie).text
                Read_nowlou = int(re.search(r'xi1">(\d+).*xi1">(\d+)</span>', user_info).group(2))  # 当前楼层
#                print("%s\r\n%s\r\n%s\r\n"%(formhash,msg,Read_nowlou))
                if Read_nowlou == tiloun-2:
                        posttime = int(time.time())
                        re_url = ('https://hostloc.com/forum.php?mod=post&action=reply&fid=45&tid=%d&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1'%(tilouid)) # post 登录接口
                        request = requests.post(re_url, {"formhash":formhash, "message":msg,"usesig":1,"subject":"","posttime":posttime}, cookies=cookie).text
                        print("跟贴成功")
                        n=1
                else:
                        print("现在有 %s 楼 |"%(Read_nowlou+1))
                        print (time.strftime("%Y-%m-%d %H:%M:%S------------------------------", time.localtime()))
                if tiloun-Read_nowlou>5:
                        time.sleep(3)
                elif tiloun-Read_nowlou>4:
                        time.sleep(0.01)
                elif tiloun-Read_nowlou==3:
                        b=0
                else:
                        n=1
        except:
                try:
                        print ("出错了,按 Ctrl+ C 停止脚本,2s 后忽略错误继续执行.")
                        time.sleep(1) 
                        print ("出错了,按 Ctrl+ C 停止脚本,1s 后忽略错误继续执行.")
                        time.sleep(1) 
                        print ("出错了,按 Ctrl+ C 停止脚本,0s 后忽略错误继续执行.")
                except KeyboardInterrupt:
                        n=1
                        print ("停止脚本执行.")

正文完
 
Blood.Cold
版权声明:本站原创文章,由 Blood.Cold 2019-10-01发表,共计1810字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。