【更新】时隔半月dz论坛自动回复器(zygx8专属)终于完工


title: 【更新】时隔半月dz论坛自动回复器(zygx8专属)终于完工
tags:

  • 小技巧

  • 小工具

categories:

    • 小工具

date: 2020-10-30 23:40:58

前言

工具:python开发环境 和 编写 python的IDE(我用的pycharm)

版本更新

4.0:在3.1的基础上

||1.优化代码
||2.彻底修复中文用户名登录问题
||3.删除原先的单页回复功能
||4.升级原先【功能3】为一键完成(包括提取百度云链接功能)--现改为 【功能1】
||5.现 【功能3】 为手动提取隐藏百度云链接功能

3.0:在2.0的基础上添加两个功能

||1.自定义回复
||2.全版块回复

3.1:在3.0的基础上

||1.优化代码
||2.修复中文用户名登录问题

2.0:2.0改为面向对象的编写方式,详细代码可以去码云查看

1.0:最初的1.0版本(代码很乱,很杂),代码我将不再公布。

4.0代码我会放在文章末尾!!

说明

  1. 除zygx8以外的其他论坛没有测试是否能用(目前正在完善中…)
  2. 该项目目前不适用于有验证码登录的论坛 (也许后期会开放cooike登录…)
  3. 该源码以及软件版权归作者个人所有!!!请勿售卖,或用于各种违法用途,本人概不负责!

使用说明【3.1】

  • 第一次打开软件需要进行配置操作,方便下次打开的的繁琐输入,如果需要更换配置(如版块的fid的值),下次打开输入1 回车操作 ,或者直接修改软件运行目录下的config.ini文件直接修改

  • 正常运行并且输入论坛账号密码后,会出现下图所示内容

    • 功能1:最常用,一般选这个就好。只要挂的时间够长,就能把选的版块下所有的帖子回复完成,并且提取隐藏内容链接

    • 功能2:用于功能1中途被关的替补,它不会去抓取论坛版块的帖子号(tid),仅从运行目录下的list.txt文件中直接读取,所以使用它一定要注意fid 和 tid是对应关系,并且要手动把功能1中已经回复过的帖子的tid去掉

    • 功能3:手动一键抓取版块下所有帖子隐藏内容链接(前提已回复完成)

  • 注意!!!:使用本软件前要在论坛签到完成后使用,使用过程中不可以手动登录论坛查看否则软件中的回帖参数值会失效

代码

其他详细内容|成品|代码 详见
我的码云Gitee

4.0代码

import requests
import re
import os
import configparser
import time
import random
import urllib3
from bs4 import BeautifulSoup
import urllib.parse
import lxml

# requests设置verify=False,控制台输出InsecureRequestWarning取消方法
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
s = requests.session()
config = configparser.ConfigParser()


class Discuz:
    def __init__(self):
        self.bbsurl = ''
        self.username = ''
        self.pwd = ''
        self.fid = ''
        self.page = 1
        self.allpage = ''
        self.timesleep = 0
        self.getpagecon = ''
        self.login_sccuess = ''
        self.len_tid =0
        print('本软件目前支持的论坛有:zygx8 || ... 完善ing \n')
        if os.path.exists('config.ini') is True:
            fix = input('是否要重新配置信息 是->1 否->输入任意数字\n: ')
            if int(fix) == 1:
                self.config()
            else:
                config.read('config.ini')
                self.bbsurl = config.get("domain", "url")
                self.username = urllib.parse.quote(config.get("login", "username").encode('utf8'))
                self.pwd = config.get("login", "pwd")
                self.fid = config.get("fid", "fid")
                self.page = config.get("list", "page")
                self.timesleep = config.get("list", "timesleep")
        else:
            self.config()

        self.login()

    def config(self):
        self.bbsurl = input('bbs url:  (such as:https://www.xxxx.com/ || 本论坛直接打1):')
        if self.bbsurl== '1':
            self.bbsurl = 'https://www.zygx8.com/'
            print(self.bbsurl)
        self.username = input('username:')
        self.username = urllib.parse.quote(self.username.encode('utf8'))
        #self.username=urllib.parse.unquote(self.username, 'utf8')#解码
        self.pwd = input('pwd:')
        self.fid = input('fid:')
        self.page = input('需要完成的page(若所有page请输入1):')
        self.timesleep = input('每篇帖子之间回复延迟 单位(s):')
        config.add_section("login")
        config.set("login", "username", urllib.parse.unquote(self.username,'utf-8'))
        config.set("login", "pwd", self.pwd)
        config.add_section("fid")

        config.set("fid", "fid", self.fid)
        config.add_section("list")
        config.set("list", "page", self.page)
        config.set("list", "timesleep", self.timesleep)
        config.add_section("domain")
        config.set("domain", "url", self.bbsurl)
        config.write(open('config.ini', "w"))

    def login(self):
        login_url = self.bbsurl + 'member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1'
        headers = {
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36'
        }
        data = {
            'fastloginfield': 'username',
            'username': self.username,
            'password': self.pwd,
            'quickforward': 'yes',
            'handlekey': 'ls'
        }
        self.login_sccuess=s.post(url=login_url, headers=headers, data=data, verify=False).text
        #print(self.login_sccuess)

    def getlist(self,page):
        list_url = '{}forum.php?mod=forumdisplay&fid={}&page={}'.format(self.bbsurl,str(self.fid),str(page))
        #print(list_url)
        list_res = s.get(url=list_url, verify=False)
        self.getpagecon = BeautifulSoup(list_res.text,'lxml')
    def gettid(self):
        if os.path.exists('list.txt'): os.remove('list.txt')
        all=self.getallpage()
        for i in range(1,int(all)+1):
            self.getlist(str(i))
            soup=self.getpagecon
            threadlisttableid = soup.select('#threadlisttableid tbody')
               #id = "normalthread_18937"
            tid=re.findall(r"'normalthread_(.*?)'",str(threadlisttableid))
            self.len_tid = self.len_tid+len(tid)
            with open('list.txt', 'a+', encoding='utf8') as f:
                for a in tid:
                    #print(i)
                    f.write(a + '\n')

    def getformhash(self):
        self.getlist(self.page)
        pageformhash = str(self.getpagecon)
        pageformhash = re.findall(r'formhash=(.*?)">退出', pageformhash)[0]
        return pageformhash

    def getallpage(self):
        self.getlist(self.page)
        allpages=re.findall(r'共 (.) 页',str(self.getpagecon))[0]
        #print('allpages:',allpages)
        return allpages

    def getPanlinks(self):
        if os.path.exists('success.txt'):os.remove('success.txt')
        with open('success.txt', 'a+', encoding='utf8') as b:
            now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            b.write('*'*15 +'\n'+now_time+'\n' + '*'*15 +'\n')
        with open('list.txt', 'r', encoding='utf8') as f:
            for tid in f.readlines():
                pan_url = 'https://www.zygx8.com/thread-{}-1-1.html'.format(tid.strip('\n'))
                content_link = s.get(pan_url).text
                soups = BeautifulSoup(content_link, "lxml")
                link = soups.select("div.showhide")
                title = re.findall(r'<span id="thread_subject">(.*?)</span>', content_link)[0]
                print(tid.strip('\n')+title)
                if '本帖隐藏的内容' in content_link:
                    #print(str(link[0])+'\n')
                    link=re.sub(r'target.*?</a>','',str(link[0])).replace(r'<div class="showhide"><h4>本帖隐藏的内容</h4>','').replace(r'  <br/>','').replace(r'</div>','').replace(r'<a href="','').replace(r'"','')
                    #print(link.replace('\n',''))
                    print('正在处理,请稍等...')
                    # i=0
                    with open('success.txt', 'a+', encoding='utf8') as f:
                        f.seek(3, 0)
                        f.write(tid.strip('\n')+title+'\n')
                        f.write(link.replace('\n',''))
                        f.write('\n')
                        f.write('\n')
                else:
                    print('错误:该帖子还没回复或没有链接'+'\n')
                    with open('success.txt', 'a+', encoding='utf8') as f:
                        f.seek(3, 0)
                        f.write(tid.strip('\n') + title + '\n')
                        f.write('错误:该帖子还没回复或没有链接')
                        f.write('\n')
                        f.write('\n')
        print('隐藏内容网盘链接提取完毕,详细见success.txt')



    def replay(self):
        print('请确认板块fid:' + self.fid + '和tid是对应关系,即将开始逐个回复...')
        #hurls = self.bbsurl + 'forum.php?mod=post&action=reply&fid=' + str(self.fid) + '&'
        hurls='{}forum.php?mod=post&action=reply&fid={}&tid='.format(self.bbsurl,str(self.fid))
        eurls = '&extra=&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1'
        formhash = self.getformhash()
        massage = [
            '666666666',
            '777777777',
            '888888888',
            '999999999',
            '111111111',
        ]
        data = {
            'select': '',
            'message': massage[random.randint(0, 4)],
            'posttime': str(int(time.time())),
            'formhash': formhash,
            'usesig': '',
            'subject': ''
        }
        with open('list.txt', 'r', encoding='utf8') as f:
            for tid in f.readlines():
                reply_url = hurls + tid.strip('\n') + eurls
                #print(reply_url)
                rep = s.post(url=reply_url, data=data)
                if '成功' in rep.text:
                    print('本次回复帖子' + tid.strip('\n') + '成功')
                else:
                    print('本次回复帖子' + tid.strip('\n') + '失败 ,原因:时间未到或其他原因,建议时间间隔310以上')
                time.sleep(int(self.timesleep))

if __name__ == '__main__':
    d = Discuz()
    print('******欢迎使用******')
    print('******功能1: ******')
    print('******1:一键功能(将一个版块下所有页的帖子回帖并在全部回复完后提取链接) ******\n')
    print('******功能2: ******')
    print('******2:自定义回贴******\n')
    print('******功能1: ******')
    print('******3:提取所有隐藏内容的百度云链接 ******\n')
    if 'window.location.href' in d.login_sccuess:
        print('账号密码正确 starting')
        fun = input('******* 请 选 择 功 能 *******\n:')
        if int(fun) == 1:
            print('***开始自动抓tid回贴 ***')
            all_page = d.getallpage()
            d.gettid()
            print('获取到', str(all_page), '页帖子,共'+str(d.len_tid)+'篇')
            d.replay()
            d.getPanlinks()
        elif int(fun) == 2:
            print('***开始自定义tid回贴 记得注意fid值噢***')
            d.replay()
        elif int(fun) == 3:
            d.getPanlinks()
    else:
        print('账号密码错误 请手动打开运行目录下的config.ini文件修改密码或者删除该文件 然后重新运行本程序!')
        input("请手动打开运行目录下的config.ini文件修改密码或者删除该文件 然后重新运行本程序"



转自https://yongees.gitee.io/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
一般论坛都会有隐藏贴,小米论坛更为严重,最近新入手了小米盒子,浏览小米论坛太痛苦了,基本上所有帖子都是隐藏贴,于是写了个半自动的回复工具。本程序不光可以在小米论坛回复,不光是恢复隐藏贴,还适用于所有的ctrl+enter模式发内容的地方哦,各位试试吧。 【ctrl+~】:自动随机选择预置回复语+两个随机表情(仅仅只适用于小米论坛的表情代码),并 ctrl+enter发送。 【ctrl+1】:自动收集经典回复语到本程序的预置内容库(好吧,就是个ini文件)。 怎么用呢,左手键盘,右手鼠标,遇到需要回复的帖子:鼠标点回复框,左手ctrl+~,搞定 如果你别的软件有快捷键ctrl+~或者是ctrl+1和本工具冲突的话,本工具是没法用的哦,需要关闭其他软件占用的快捷键。好多软件的老板键都是ctrl+~,请各位注意。另外如果回复的时候需要验证码,可能就有点郁闷,只能粘贴回复语,不能直接提交。。 逛论坛的时候,发现别人发的回复语,比较通用型的那种,鼠标选取起来,然后ctrl+1,这个回复语就到了咱的库里了,等你ctrl+~回复的时候就能用上了,退出程序可点击右下角托盘区图标,还有暂停功能哦。 如果是在别的论坛发帖或者是聊QQ的时候,不需要回复有那个小米论坛的表情代码后缀,可以打开配置文件设置一下,配置文件里面有说明。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值