Created
February 15, 2025 16:05
-
-
Save c80609a/ead1428f32a0f696a574d09681cb3b98 to your computer and use it in GitHub Desktop.
Скрипт капчевания двача by AI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from peewee import SqliteDatabase, Model, AutoField, TextField, IntegerField | |
import time | |
# Имя базы данных | |
db = SqliteDatabase("threads.db") | |
# Определение модели | |
class Post(Model): | |
id = AutoField() | |
post_num = IntegerField() # Автоинкрементный первичный ключ | |
text = TextField() # Поле для текста (обязательное) | |
class Meta: | |
database = db # Указываем, какую БД использовать | |
table_name = "posts" # Явно задаем имя таблицы | |
# Создание таблицы (если её нет) | |
db.connect() | |
db.create_tables([Post]) | |
def check_threads(i): | |
cookies = { | |
'_ga': 'GA1.2.1175102694.1739632392', | |
'_gid': 'GA1.2.486053987.1739632392', | |
'_gat': '1', | |
'cf_clearance': 'EMZe.oR_VFakXQz2unqClOuJrdd2l0Op94pXfKghfmY-1739632392-1.2.1.1-sG2UG3tpY2zml6Iqe20skn8XnmmZHDNPtG1QXkzcsvRp2hrUhHt43e3PMGxTV0ZD9hn6yCgbEAqB6BfjCY09OzrMAv6h9gMTytEdroAr1oBUwnmRlBhD4BovcG6xNUSZcUYR512bxuZhg5Sg2_0CCZTSGhjPpzKHq.brnhxlwNbFO1cusRDMVMkKFUrH4YqUysp.OpEPQtfG1pbeDJtH9_xTN1QbTEj4dSTSfamb8hZ77X9sZ8UwpGKp59Nb8n6bJ9EFG7oUEdGzABgJni_nxEjEa0Wcxw0sAB.vi8DV_EQ', | |
'_ga_7NPYTX0FY3': 'GS1.2.1739632392.1.0.1739632392.0.0.0', | |
} | |
headers = { | |
'accept': 'text/html, */*; q=0.01', | |
'accept-language': 'en-US,en;q=0.9', | |
# 'cookie': '_ga=GA1.2.1175102694.1739632392; _gid=GA1.2.486053987.1739632392; _gat=1; cf_clearance=EMZe.oR_VFakXQz2unqClOuJrdd2l0Op94pXfKghfmY-1739632392-1.2.1.1-sG2UG3tpY2zml6Iqe20skn8XnmmZHDNPtG1QXkzcsvRp2hrUhHt43e3PMGxTV0ZD9hn6yCgbEAqB6BfjCY09OzrMAv6h9gMTytEdroAr1oBUwnmRlBhD4BovcG6xNUSZcUYR512bxuZhg5Sg2_0CCZTSGhjPpzKHq.brnhxlwNbFO1cusRDMVMkKFUrH4YqUysp.OpEPQtfG1pbeDJtH9_xTN1QbTEj4dSTSfamb8hZ77X9sZ8UwpGKp59Nb8n6bJ9EFG7oUEdGzABgJni_nxEjEa0Wcxw0sAB.vi8DV_EQ; _ga_7NPYTX0FY3=GS1.2.1739632392.1.0.1739632392.0.0.0', | |
'priority': 'u=1, i', | |
'referer': 'https://2ch.hk/b/', | |
'sec-ch-ua': '"Not A(Brand";v="8", "Chromium";v="132", "Google Chrome";v="132"', | |
'sec-ch-ua-mobile': '?0', | |
'sec-ch-ua-platform': '"Windows"', | |
'sec-fetch-dest': 'empty', | |
'sec-fetch-mode': 'cors', | |
'sec-fetch-site': 'same-origin', | |
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36', | |
'x-requested-with': 'XMLHttpRequest', | |
} | |
print(f'https://2ch.hk/b/{i}.json') | |
response = requests.get(f'https://2ch.hk/b/{i}.json', cookies=cookies, headers=headers) | |
if response.status_code == 200: | |
for thread in response.json()['threads']: | |
try: | |
post_num = thread['posts'][0]['num'] | |
text = thread['posts'][0]['comment'] | |
post = Post.get_or_none(Post.post_num == post_num) | |
if post is None: | |
Post.create(post_num=post_num, text=text) | |
print(f'{post_num} нашел новый тред') | |
except Exception as e: | |
print('Ошибка', e) | |
continue | |
return True | |
else: | |
return False | |
while True: | |
for i in range(1, 100): | |
res = check_threads(i) | |
time.sleep(180) | |
if res is False: | |
break | |
time.sleep(3600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment