适用于 NexusPHP 搭起来的 PT 站,前提是对方没魔改。
依赖 tesseract pytesseract requests BeautifulSoup
#! /usr/bin/env python3
# -*- coding:utf-8 -*-
import re
import logging
import requests
import pytesseract
from io import BytesIO
from PIL import Image
from urllib.parse import urljoin
from bs4 import BeautifulSoup
logging.basicConfig(filename='ptsign.log',filemode='a',level=logging.INFO,format='%(asctime)s - %(message)s',datefmt='%d-%b-%y %H:%M:%S')
class PreImage(object):
def __init__(self,image):
self.image = Image.open(image).convert('L')
def image_to_bin(self,threshold=120):
pixdata = self.image.load()
w, h = self.image.size
for y in range(h):
for x in range(w):
if pixdata[x, y] < threshold:
pixdata[x, y] = 0
else:
pixdata[x, y] = 255
return self.image
def delete_point(self):
pixdata = self.image.load()
w,h = self.image.size
for y in range(1,h-1):
for x in range(1,w-1):
count = 0
if pixdata[x,y-1] > 245:
count = count + 1
if pixdata[x,y+1] > 245:
count = count + 1
if pixdata[x-1,y] > 245:
count = count + 1
if pixdata[x+1,y] > 245:
count = count + 1
if pixdata[x-1,y-1] > 245:
count = count + 1
if pixdata[x-1,y+1] > 245:
count = count + 1
if pixdata[x+1,y-1] > 245:
count = count + 1
if pixdata[x+1,y+1] > 245:
count = count + 1
if count > 6:
pixdata[x,y] = 255
return self.image
def to_string(self):
regex = r"[\'\"\*~!@#$%^&\+\\n\\r;:,\ \_\-\)\(’‘“”]"
image = self.image_to_bin()
image = self.delete_point()
imagestring = pytesseract.image_to_string(image)
imagestring = re.sub(regex,'',imagestring)
logging.info('imagestring: {}'.format(imagestring))
return imagestring
class NexusPHP(object):
user_agent = "Mozilla/5.0 (Windows10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.36 Safari/537.36"
def __init__(self,url='https://hdhome.org',user_agent=user_agent):
self.url = url
self.session = requests.Session()
self.session.headers.update({'user-agent':user_agent})
self.session.headers.update({'origin':self.url})
self.session.headers.update({'referer':urljoin(self.url,'login.php')})
def login(self,username,password):
url=urljoin(self.url,'takelogin.php')
imagestring = self._get_login_imagestring()
imagehash = self._get_login_imagehash()
playload = {'imagestrig':imagestring,
'imagehash':imagehash,
'username':username,
'passowrd':password}
r = self.session.post(url,playload,timeout=6)
logging.info('get {} code {}'.format(url,str(r.status_code)))
return self.is_logged_in(r)
def _get_login_imagestring(self):
url = urljoin(self.url,'login.php')
r = self.session.get(url,timeout=6)
soup = BeautifulSoup(r.text,"html.parser")
img = soup.find_all("img")
for i in img:
if 'image' in i['src']:
imgurl = urljoin(self.url,i['src'])
image = self.session.get(imgurl)
image = BytesIO(image.content)
image = PreImage(image)
return image.to_string()
def _get_login_imagehash(self):
url = urljoin(self.url,'login.php')
r = self.session.get(url,timeout=6)
soup = BeautifulSoup(r.text,"html.parser")
imagehash = soup.find("input",{"name":"imagehash"})
assert imagehash and imagehash['value'],"there is no imagehash on this page"
logging.info('imagehash: {}'.format(imagehash['value']))
return imagehash['value']
def is_logged_in(self,r):
url=urljoin(self.url,'index.php')
if r:
r = self.session.get(url,timeout=6)
return 'Pls keep seeding' in r.text
def sign(self):
url = urljoin(self.url,'attendance.php')
self.session.headers.update({'referer':urljoin(self.url,'index.php')})
self.session.headers.update({'upgrade-insecure-requests':'1'})
r = self.session.get(url,allow_redirects=False,timeout=6)
logging.info('get {} code {}'.format(url,str(r.status_code)))
return r
def main():
import time
from random import randrange
username = 'hdhome' #修改成自己的账号
password = 'hdhome' #修改成自己的密码
gzt = NexusPHP('https://pt.gztown.net') #修改成正确的 PT 站点名称
for i in range(1,8):
time.sleep(randrange(5))
logging.info('{} times trying'.format(i))
gzt.login(username,password)
time.sleep(randrange(5))
r = gzt.sign()
if r.status_code == 200:
logging.info('sign success')
break
else:
logging.info('sign failure')
continue
if __name__ == '__main__':
main()
1
alvin666 2018-11-26 13:20:25 +08:00 via Android
我自己写了一个用 selenium 的(懒)
还有个油猴的 autothank 脚本 我感觉最厉害的应该是 autoseed 吧 emmmm |
3
29EtwXn6t5wgM3fD 2018-11-26 13:32:00 +08:00
看起来不错 然而混的 PT 站签到需要看图识片
|
4
bearqq 2018-11-26 13:32:08 +08:00
hdhome 直接把 cookies 拿出来,把签到链接做个请求就好了,也没有验证码什么的,别的站不太清楚。
|
5
KickAssTonight 2018-11-26 14:55:46 +08:00 1
hdhome 直接 curl 就行了。
```sh #!/bin/sh curl -I -H "cookie:'your_cookie'" https://hdhome.org/attendance.php ``` |
6
Sylv 2018-11-26 15:09:07 +08:00 via iPhone
qiandao.today 了解下,建个模板比写这堆代码方便多了。另外,大部分 nexus 站的 cookies 都是不会过期的,所以没必要做验证码识别,直接用 cookies 就好。
|
7
Heavytiger 2018-11-26 15:21:47 +08:00
不如你们邀请我进一个 PT 站,先
|
8
ZhangSanAleph 2018-11-26 17:26:07 +08:00
ourbits 也可以直接用 curl+cookie 签到
|
9
weizhiyao008 2018-11-26 17:37:12 +08:00
魔力值多到用不完
|
10
Mac 2018-11-26 17:52:27 +08:00 via Android
每年几十万只能买徽章玩
|
11
goodryb 2018-11-26 18:02:56 +08:00
之前也写了一个,验证码识别用的的百度的 ocr,不过后来想想签到也没啥用,魔力够多了,倒是可以防止忘记登录被 ban
|
12
zst 2018-11-26 18:08:35 +08:00 via Android
可惜 byr 不能用签到换魔力值
|
13
ucun OP |
14
af435727271 2019-01-10 20:51:38 +08:00 via Android
@ZhangSanAleph 零基础求指导
|
15
af435727271 2019-01-10 20:54:02 +08:00 via Android
@KickAssTonight 可以指导下吗 cookies 后面的东西怎么替换成自己的网站的
|
16
af435727271 2019-01-10 20:54:45 +08:00 via Android
@bearqq 签到请求怎么获取 可以具体说下吗
|
17
KickAssTonight 2019-02-13 14:35:54 +08:00
@af435727271 用 Chrome 浏览器,打开开发者工具,切到 Network 这个 tab,然后登录网站,在请求里就能拿到 cookie 了。
|
18
af435727271 2019-02-17 13:37:48 +08:00
@KickAssTonight 已经抓取签到请求,套套哥无法执行签到,用 putty 登录路由器,发现无法粘贴全部命令 同样方法在另外一个 pt 站签到成功了 请问一下,这是什么原因?
|
19
af435727271 2019-02-17 13:44:54 +08:00
@KickAssTonight 复制种子页面或者 21 点签到请求,在 putty 上执行,发现套套哥跟皇后会出现乱码,最后出现好多大写的 putty 字样,其他 pt 站上则正常
|
20
af435727271 2019-02-17 15:47:54 +08:00 via Android
@KickAssTonight 我是在 chrome 的开发者模式中,点击签到后找到签到请求,类似 signin.php checkin.php ,然后再右击 copy as curl(bash),不知道这个是不您说的 curl+cookies 签到,如果不是,请您花两分钟指导一下,万分感谢
|
21
af435727271 2019-02-18 01:20:17 +08:00 via Android
@KickAssTonight cookies 复制的是 signed.php 的 Headers--Request Headers 的 cookies,后面的网址是主网址再加 /signed.php ,但没成功签到 是不是哪里错了
|
22
yuhaaitao 2020-02-09 21:15:13 +08:00
搭建不容易
|