-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
88 lines (66 loc) · 2.53 KB
/
main.py
File metadata and controls
88 lines (66 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import time
import requests
from dotenv import load_dotenv
# Cargar variables de entorno desde el archivo .env
load_dotenv()
# Configuracion de la API de CapSolver
CAPSOLVER_API_KEY = os.getenv("CAPSOLVER_API_KEY")
CREATE_TASK_URL = "https://api.capsolver.com/createTask"
GET_RESULT_URL = "https://api.capsolver.com/getTaskResult"
# Configuracion del sitio web objetivo
# Reemplaza con tu sitio objetivo
SITE_URL = "https://www.google.com"
SITE_KEY = "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_kl-"
PAGE_ACTION = "login" # Parametro de accion de grecaptcha.execute
def create_task():
"""Crear una tarea de resolucion de ReCaptcha V3."""
payload = {
"clientKey": CAPSOLVER_API_KEY,
"task": {
"type": "ReCaptchaV3TaskProxyLess",
"websiteURL": SITE_URL,
"websiteKey": SITE_KEY,
"pageAction": PAGE_ACTION
}
}
response = requests.post(CREATE_TASK_URL, json=payload)
result = response.json()
if result.get("errorId") != 0:
raise Exception(f"Error al crear la tarea: {result.get('errorDescription')}")
return result.get("taskId")
def get_task_result(task_id):
"""Consultar el resultado de la tarea hasta que este listo."""
payload = {
"clientKey": CAPSOLVER_API_KEY,
"taskId": task_id
}
while True:
response = requests.post(GET_RESULT_URL, json=payload)
result = response.json()
if result.get("errorId") != 0:
raise Exception(f"Error al obtener el resultado: {result.get('errorDescription')}")
status = result.get("status")
if status == "ready":
return result.get("solution")
elif status == "processing":
print("La tarea aun se esta procesando, esperando...")
time.sleep(2)
else:
raise Exception(f"Estado desconocido: {status}")
def main():
if not CAPSOLVER_API_KEY:
print("Error: CAPSOLVER_API_KEY no encontrada en el archivo .env")
print("Por favor, crea un archivo .env con tu clave API:")
print("CAPSOLVER_API_KEY=tu_clave_api_aqui")
return
print("Creando tarea de resolucion de ReCaptcha V3...")
print(f"Accion de pagina: {PAGE_ACTION}")
task_id = create_task()
print(f"Tarea creada exitosamente! ID de tarea: {task_id}")
print("Esperando la solucion...")
solution = get_task_result(task_id)
print("\nSolucion recibida!")
print(f"gRecaptchaResponse: {solution.get('gRecaptchaResponse')[:100]}...")
if __name__ == "__main__":
main()