Merhaba, captcha çözümü için bir kod yazdım. Ekrana gelen captcha'nın resmi dosyalar içerisine kaydediliyor, kaydedilen resim 2captcha'ya gönderilerek çözülüyor. Çözüm alınıyor ve alındıktan sonra klavye aracılığı ile 4 haneli sayı ve harflerden oluşan captcha kodunu ekrana girme bölümünde sorun yaşıyorum. Kullandığım kütüphaneden dolayı integer hatası alıyorum. Captcha kodlarında integer algılanmadığı için hata veriyor ve kodu giremiyor. Tahminimce aşağıda verdiğim kütüphanede integer beklentisi içinde olduğu için diğer harfleri algılayamıyor ve hata veriyor. Bu konuda nasıl bir yol izlemem lazım, yardımcı olabilir misiniz.
Bunlar benim kodlarım
import tkinter as tk
from threading import Thread
import pyautogui
import time
from clicksend import *
import threading
from PIL import ImageGrab
import keyboard
from pynput import keyboard
import pygame
from twocaptcha import TwoCaptcha
import requests
from pynput.keyboard import Controller as KeyboardController
keycodes = {
"F1": 0x3B, "F2": 0x3C, "F3": 0x3D, "F4": 0x3E, "F5": 0x3F, "F6": 0x40, "F7": 0x41, "F8": 0x42, "F9": 0x43, "F10": 0x44, "F11": 0x57, "F12": 0x58,
"0": 0x0B, "1": 0x02, "2": 0x03, "3": 0x04, "4": 0x05, "5": 0x06, "6": 0x07, "7": 0x08, "8": 0x09, "9": 0x0A,
"A": 0x1E, "B": 0x30, "C": 0x2E, "D": 0x20, "E": 0x12, "F": 0x21, "G": 0x22, "H": 0x23, "I": 0x17, "J": 0x24, "K": 0x25, "L": 0x26, "M": 0x32, "N": 0x31, "O": 0x18, "P": 0x19, "Q": 0x10, "R": 0x13, "S": 0x1F, "T": 0x14, "U": 0x16, "V": 0x2F, "W": 0x11, "X": 0x2D, "Y": 0x15, "Z": 0x2C,
"ESC": 0x01, "TAB": 0x0F, "ENTER": 0x1C,
"DOWN_ARROW": 0x50, "UP_ARROW": 0x48, "RIGHT_ARROW": 0x4D, "LEFT_ARROW": 0x4B,
"NUMPAD_0": 0x52, "NUMPAD_1": 0x4F, "NUMPAD_2": 0x50, "NUMPAD_3": 0x51, "NUMPAD_4": 0x4B, "NUMPAD_5": 0x4C, "NUMPAD_6": 0x4D, "NUMPAD_7": 0x47, "NUMPAD_8": 0x48, "NUMPAD_9": 0x49,
}
# Klavye kontrolcüsünü oluştur
keyboard = KeyboardController()
tusbas = KeyboardDriver()
mousebas = MouseDriver()
resim_captcha = r'C:\makro\resimler\captcha.png'
image_path = r'C:\makro\resimler\deneme.png'
# Bir kilit oluştur
lock = threading.Lock()
class CaptchaSolver:
def __init__(self, master, api_key):
self.api_key = api_key
self.upload_url = 'https://2captcha.com/in.php'
self.running = True
self.captcha_basla_checkbutton_var = tk.BooleanVar()
self.captcha_basla_checkbutton_var.set(False)
self.tusbas = keyboard.type
def captcha_bul(self):
try:
# Ekranı tarayarak belirli bir resmi ara
resim_konumu = pyautogui.locateOnScreen(resim_captcha, confidence=0.9)
return resim_konumu
except:
return None
def captcha_basla(self):
# Aranan resmi bul
resim_konumu = self.captcha_bul()
# Eğer resim bulunamazsa 5 saniye bekle ve döngüye devam et
if resim_konumu is None:
time.sleep(1)
# Belirli bir resim bulunduğunda yapılacak işlemi buraya yazabilirsiniz
task_id = self.koordinat_screen(resim_konumu)
if task_id:
captcha_result = self.check_result(task_id)
if captcha_result:
return captcha_result
# 10 saniye bekle
time.sleep(1)
def koordinat_screen(self, resim_konumu):
# Merkez noktayı hesapla
x, y, w, h = resim_konumu
merkez_x = x + (w / 2)
merkez_y = y + (h / 2)
# Ekranın tamamını al
screen = ImageGrab.grab()
# Dikdörtgenin koordinatlarını hesapla
x1 = int(merkez_x - 275)
x2 = int(merkez_x - 40)
y1 = int(merkez_y - 14)
y2 = int(merkez_y + 50)
# Dikdörtgeni kes
region = screen.crop((x1, y1, x2, y2))
# Kesilen bölgeyi belirtilen dizine kaydet
save_path = "C:\\makro\\resimler\\captcharesmi.png"
region.save(save_path)
print("Resim kaydedildi:", save_path)
# Captcha çözme işlemini başlat
return self.solve_captcha(save_path)
def solve_captcha(self, image_path):
with open(image_path, 'rb') as file:
upload_data = {'key': self.api_key, 'method': 'post'}
files = {'file': file}
response = requests.post(self.upload_url, data=upload_data, files=files)
response_data = response.text
if response_data.startswith('OK|'):
task_id = response_data.split('|')[1]
print("İşlem kimliği:", task_id)
return task_id
else:
print("Hata:", response_data)
return None
def check_result(self, task_id):
while True:
# 2Captcha'ya sonuç sorgusu yap
check_url = f"https://2captcha.com/res.php?key={self.api_key}&action=get&id={task_id}"
check_response = requests.get(check_url)
check_data = check_response.text
# 2Captcha yanıtı 'CAPCHA_NOT_READY' ise, biraz bekleyip tekrar kontrol et
if check_data == 'CAPCHA_NOT_READY':
time.sleep(5)
continue
# 2Captcha yanıtı '|' içeriyorsa, işlem tamamlandı demektir
elif '|' in check_data:
# Captcha sonucunu al
captcha_result = check_data.split('|')[1]
print("Captcha çözüldü:", captcha_result)
# Captcha sonucunu girme işlemi
if self.captchagirme(captcha_result):
# Sonuç döndür
return captcha_result
else:
print("Captcha çözülmedi veya uygun formatta değil.")
return None
# Beklenmedik bir hata varsa, hata mesajını yazdır ve None döndür
else:
print("Beklenmedik bir hata oluştu:", check_data)
return None
def captchagirme(self, captcha_result):
# Doğru formatta bir captcha sonucu alındıysa devam et
if captcha_result and captcha_result.isdigit(): # Sadece sayısal değerler kabul edilecek
# Captcha sonucunu not defterine kaydet
with open("C:\\makro\\captchakodu.txt", "w") as file:
file.write(captcha_result)
# Resim captchanın konumunu bul
resim_captcha = self.captcha_bul()
# Doğru formatta bir captcha sonucu alındıysa devam et
if resim_captcha:
# Resim captchanın merkez noktasını bul
x, y, w, h = resim_captcha
merkez_x = x + (w / 2)
merkez_y = y + (h / 2)
# Sol tıklama işlevi (merkez noktasına göre)
x22 = merkez_x - 33
y22 = merkez_y + 79
mousebas.leftclick(0.2, x22, y22)
# Not defterinden captcha kodunu oku
with open("C:\\makro\\captchakodu.txt", "r") as file:
captchakodu = file.read()
# Klavye girişi ile captcha kodunu yaz
if tusbas.tusbas(captchakodu, 0.5):
return True
else:
return False
else:
print("Captcha resmi bulunamadı.")
return False
else:
print("Captcha çözülmedi veya uygun formatta değil.")
return False
# Tkinter uygulamasını başlat
root = tk.Tk()
# CaptchaSolver sınıfını oluştururken root penceresini parametre olarak iletebilirsiniz
captcha_solver = CaptchaSolver(api_key="2captcha_api_Key")
# Captcha çözümünü başlat
captcha_solver.captcha_basla()
# Tkinter uygulamasını çalıştır
root.mainloop()Bunlar da hata aldığım kütüphane kodları
import struct
class stroke():
@property
def data(self):
raise NotImplementedError
@property
def data_raw(self):
raise NotImplementedError
class mouse_stroke(stroke):
fmt = 'HHsiiI' # 's' karakter tipi ile her türlü karakteri algılayacak
fmt_raw = 'HHHHIsiiI' # 's' karakter tipi ile her türlü karakteri algılayacak
state = 0
flags = 0
rolling = 0
x = 0
y = 0
information = 0
def __init__(self,state,flags,rolling,x,y,information):
super().__init__()
self.state =state
self.flags = flags
self.rolling = rolling
self.x = x
self.y = y
self.information = information
@staticmethod
def parse(data):
return mouse_stroke(*struct.unpack(mouse_stroke.fmt,data))
@staticmethod
def parse_raw(data):
unpacked= struct.unpack(mouse_stroke.fmt_raw,data)
return mouse_stroke(
unpacked[2],
unpacked[1],
unpacked[3],
unpacked[5],
unpacked[6],
unpacked[7])
@property
def data(self):
data = struct.pack(self.fmt,
self.state,
self.flags,
self.rolling,
self.x,
self.y,
self.information)
return data
@property
def data_raw(self):
data = struct.pack(self.fmt_raw,
0,
self.flags,
self.state,
self.rolling,
0,
self.x,
self.y,
self.information)
return data
class key_stroke(stroke):
fmt = 'HHsI' # 's' karakter tipi ile her türlü karakteri algılayacak
fmt_raw = 'HHHHIsI' # 's' karakter tipi ile her türlü karakteri algılayacak
code = 0
state = 0
information = 0
def __init__(self,code,state,information):
super().__init__()
self.code = code
self.state = state
self.information = information
@staticmethod
def parse(data):
return key_stroke(*struct.unpack(key_stroke.fmt,data))
@staticmethod
def parse_raw(data):
unpacked= struct.unpack(key_stroke.fmt_raw,data)
return key_stroke(unpacked[1],unpacked[2],unpacked[4])
@property
def data(self):
data = struct.pack(self.fmt,self.code,self.state,self.information)
return data
@property
def data_raw(self):
data = struct.pack(self.fmt_raw,0,self.code,self.state,0,self.information)
return data