站内大佬写的某某堂自动回帖并签到脚本,我只有一个号用不过来,分享给有需要的MJJ,能量较高,不够就哭。
Python脚本,部署基本就是装下依赖然后执行。
[pay]
```
import time
import random
import httpx
from lxml import etree
import re
class Checkin:
def init(self):
proxies = {
“http://”: “http://127.0.0.1:20171”,
“https://”: “http://127.0.0.1:20171”,
}
#self.client = httpx.Client(http2=True, proxies=proxies)
self.client = httpx.Client(http2=True)
self._safe()
def _safe(self):
res = self.client.get('https://sehuatang.net/')
pattern = r"var safeid='(.+?)';"
match = re.search(pattern, res.text)
if match:
safeid = match.group(1)
self.client.cookies.set('_safe', safeid)
print(f"safeid: {safeid}")
else:
raise ValueError("_safe获取失败")
def _formhash(self):
res = self.client.get('https://sehuatang.net/')
tree = etree.HTML(res.text)
try:
self.formhash = tree.xpath('//input[@name="formhash"]/@value')[0]
return self.formhash
except:
raise ValueError("formhash获取失败")
def login(self, username, password):
formhash = self._formhash()
print('登录formhash', formhash)
data = {
'fastloginfield': 'username',
'username': username,
'cookietime': '2592000',
'password': password,
'formhash': formhash,
'quickforward': 'yes',
'handlekey': 'ls'
}
url = 'https://sehuatang.net/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1'
res = self.client.post(url=url, data=data)
print(res.text)
print(res.cookies)
formhash = self._formhash()
print('回复formhash', formhash)
def home(self):
url = 'https://sehuatang.net/home.php?mod=spacecp&ac=credit&showcredit=1'
res = self.client.get(url)
print(res.text)
def reply(self, fid, tid, message):
"""
回复主题、评论主题
:param fid: 板块id
:param tid: 主题id
:param message: 回复内容
:return: 响应结果
"""
params = {
'mod': 'post',
'action': 'reply',
'fid': fid,
'tid': tid,
'extra': 'page=1',
'replysubmit': 'yes',
'infloat': 'yes',
'handlekey': 'fastpost',
'inajax': '1'
}
data = {
'file': '',
'message': message,
'posttime': int(time.time()),
'formhash': self.formhash,
'usesig': '',
'subject': ' '
}
# self._checkpostrule()
url = 'https://sehuatang.net/forum.php'
headers = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'accept-language': 'zh-CN,zh;q=0.9',
'cache-control': 'no-cache',
'content-type': 'application/x-www-form-urlencoded',
'origin': 'https://sehuatang.net',
'pragma': 'no-cache',
'priority': 'u=0, i',
'referer': 'https://sehuatang.net/forum.php?mod=viewthread&tid=2136584&extra=page%3D1',
'sec-ch-ua': '"Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'iframe',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'same-origin',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
}
res = self.client.post(url, params=params, data=data)
print('reply'.center(50, '='))
print(self.client.cookies)
print(res.url, data)
print(res.text)
print('reply'.center(50, '='))
def _signhash_and_secqaahash(self):
"""
获取签到需要的signhash参数和secqaahash参数
:return: signhash, secqaahash
"""
params = {
'id': 'dd_sign',
'ac': 'sign',
'infloat': 'yes',
'handlekey': 'pc_click_ddsign',
'inajax': '1',
'ajaxtarget': 'fwin_content_pc_click_ddsign'
}
res = self.client.get('https://sehuatang.net/plugin.php', params=params)
# 匹配signhash
pattern = r'signhash=(.+?)"'
match = re.search(pattern, res.text)
if match:
signhash = match.group(1)
else:
raise ValueError("signhash获取失败")
# 匹配secqaahash
pattern = r"updatesecqaa\('(.+?)'"
match = re.search(pattern, res.text)
if match:
secqaahash = match.group(1)
else:
raise ValueError("idhash获取失败")
return signhash, secqaahash
def _sectplcode(self, idhash):
"""
获取验证码并计算结果
:return: 验证码结果
"""
params = {
'mod': 'secqaa',
'action': 'update',
'idhash': idhash,
str(random.random()): None
}
headers = {
"Referer": "https://sehuatang.net/plugin.php?id=dd_sign"
}
res = self.client.get('https://sehuatang.net/misc.php', params=params, headers=headers)
pattern = r"(\d+\s*[\+\-\*/]\s*\d+)"
match = re.search(pattern, res.text)
if match:
sectplcode = match.group(1)
print('验证码', sectplcode)
else:
raise ValueError("验证码获取失败")
# 此方法不安全, 这是执行python代码,自己修改成安全的方法
secverify = eval(sectplcode)
return secverify
def dd_sign(self):
signhash, secqaahash = self._signhash_and_secqaahash()
idhash = secqaahash
secverify = self._sectplcode(idhash)
print('验证码计算结果', secverify)
params = {
'id': 'dd_sign',
'ac': 'sign',
'signsubmit': 'yes',
'handlekey': 'pc_click_ddsign',
'signhash': signhash,
'inajax': '1'
}
data = {
'formhash': self.formhash,
'signtoken': '',
'secqaahash': secqaahash,
'secanswer': secverify
}
res = self.client.post('https://sehuatang.net/plugin.php', params=params, data=data)
print(res.text)
@staticmethod
def _parsing_tid(href):
pattern = r"tid=(.+?)&"
match = re.search(pattern, href)
if match:
# https://sehuatang.net/forum.php?mod=viewthread&tid=2138356&extra=page%3D1
tid = match.group(1)
return tid
else:
print(ValueError("tid获取失败"))
def forum_display(self, fid, page=None):
params = {
'mod': 'forumdisplay',
'fid': fid,
'page': page
}
res = self.client.get('https://sehuatang.net/forum.php', params=params)
tree = etree.HTML(res.text)
content_list = tree.xpath('//*[@id="waterfall"]/li')
tid_list = []
for content in content_list:
href = ''.join(content.xpath('./div[1]/a/@href'))
title = ''.join(content.xpath('./div[1]/a/img/@alt'))
duration = ''.join(content.xpath('./div[1]/a/div/text()'))
tid = self._parsing_tid(href)
print(title, duration, tid)
tid_list.append(tid)
print(tid_list)
if name == ‘main’:
tid_list = [‘2138356’, ‘2138352’, ‘2138350’, ‘2138349’, ‘2138347’, ‘2138346’, ‘2138344’, ‘2138343’, ‘2138342’,
‘2138341’,
‘2138339’, ‘2138337’, ‘2138336’, ‘2138333’, ‘2138331’, ‘2138329’, ‘2138323’, ‘2138321’, ‘2138319’,
‘2138317’,
‘2138302’, ‘2138301’, ‘2138299’, ‘2138296’, ‘2138295’, ‘2136588’, ‘2136586’, ‘2136585’, ‘2136584’,
‘2136582’]
message_list = [
“感谢分享”,
“给力给力”,
“不错不错”,
“太骚了。给力”,
“多谢楼主分享”,
“厉害了!”,
“这个好,谢谢分享”,
“不错,够骚”,
“长得好看的很”,
“就是喜欢这种的”,
“好看 刺激哦”,
“这个真好看”
]
sehuatang = Checkin()
sehuatang.login(‘用户名’, ‘密码’)
sehuatang.forum_display(41)
message = random.choice(message_list)
tid = random.choice(tid_list)
sehuatang.reply(‘41’, tid, message)
print(tid, message)
sehuatang.dd_sign()
sehuatang.home()
```
[/pay]