rcap-client 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rcap_client-1.0.1/LICENSE +21 -0
- rcap_client-1.0.1/PKG-INFO +57 -0
- rcap_client-1.0.1/README.md +37 -0
- rcap_client-1.0.1/pyproject.toml +28 -0
- rcap_client-1.0.1/rcap_client/__init__.py +0 -0
- rcap_client-1.0.1/rcap_client/api.py +32 -0
- rcap_client-1.0.1/rcap_client/example.py +15 -0
- rcap_client-1.0.1/rcap_client/solver.py +299 -0
- rcap_client-1.0.1/rcap_client/utils.py +102 -0
- rcap_client-1.0.1/rcap_client.egg-info/PKG-INFO +57 -0
- rcap_client-1.0.1/rcap_client.egg-info/SOURCES.txt +13 -0
- rcap_client-1.0.1/rcap_client.egg-info/dependency_links.txt +1 -0
- rcap_client-1.0.1/rcap_client.egg-info/requires.txt +5 -0
- rcap_client-1.0.1/rcap_client.egg-info/top_level.txt +1 -0
- rcap_client-1.0.1/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mahdi-marjani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rcap-client
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: rcap client for solving reCAPTCHA challenges.
|
|
5
|
+
Author-email: Mahdi Marjani <mahdi.marjani.dev@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mahdi-marjani/rcap-client
|
|
8
|
+
Project-URL: Documentation, https://github.com/mahdi-marjani/rcap-client
|
|
9
|
+
Project-URL: Repository, https://github.com/mahdi-marjani/rcap-client.git
|
|
10
|
+
Project-URL: Issues, https://github.com/mahdi-marjani/rcap-client/issues
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy>=2.2.6
|
|
15
|
+
Requires-Dist: Pillow>=12.1.0
|
|
16
|
+
Requires-Dist: Requests>=2.32.5
|
|
17
|
+
Requires-Dist: selenium>=4.39.0
|
|
18
|
+
Requires-Dist: webdriver_manager>=4.0.2
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# rcap-client
|
|
22
|
+
|
|
23
|
+
rcap client for solving reCAPTCHA using Selenium and rcap server.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
Install via pip:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
pip install rcap-client
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Here's an example of how to use it:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from selenium import webdriver
|
|
39
|
+
from selenium.webdriver.firefox.service import Service
|
|
40
|
+
from webdriver_manager.firefox import GeckoDriverManager
|
|
41
|
+
from rcap_client.solver import RecaptchaSolver
|
|
42
|
+
|
|
43
|
+
driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))
|
|
44
|
+
driver.get("https://www.google.com/recaptcha/api2/demo")
|
|
45
|
+
|
|
46
|
+
solver = RecaptchaSolver(driver)
|
|
47
|
+
solver.solve() # Done!
|
|
48
|
+
|
|
49
|
+
print("reCAPTCHA solved!")
|
|
50
|
+
input("Press Enter to quit...")
|
|
51
|
+
driver.quit()
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Details
|
|
55
|
+
|
|
56
|
+
- Uses Selenium for browser interaction.
|
|
57
|
+
- Relies on a local API (localhost:8000) for image detection.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# rcap-client
|
|
2
|
+
|
|
3
|
+
rcap client for solving reCAPTCHA using Selenium and rcap server.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install via pip:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pip install rcap-client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Here's an example of how to use it:
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from selenium import webdriver
|
|
19
|
+
from selenium.webdriver.firefox.service import Service
|
|
20
|
+
from webdriver_manager.firefox import GeckoDriverManager
|
|
21
|
+
from rcap_client.solver import RecaptchaSolver
|
|
22
|
+
|
|
23
|
+
driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))
|
|
24
|
+
driver.get("https://www.google.com/recaptcha/api2/demo")
|
|
25
|
+
|
|
26
|
+
solver = RecaptchaSolver(driver)
|
|
27
|
+
solver.solve() # Done!
|
|
28
|
+
|
|
29
|
+
print("reCAPTCHA solved!")
|
|
30
|
+
input("Press Enter to quit...")
|
|
31
|
+
driver.quit()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Details
|
|
35
|
+
|
|
36
|
+
- Uses Selenium for browser interaction.
|
|
37
|
+
- Relies on a local API (localhost:8000) for image detection.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rcap-client"
|
|
7
|
+
version = "1.0.1"
|
|
8
|
+
description = "rcap client for solving reCAPTCHA challenges."
|
|
9
|
+
authors = [{name = "Mahdi Marjani", email = "mahdi.marjani.dev@gmail.com"}]
|
|
10
|
+
license = "MIT"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.8"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"numpy>=2.2.6",
|
|
15
|
+
"Pillow>=12.1.0",
|
|
16
|
+
"Requests>=2.32.5",
|
|
17
|
+
"selenium>=4.39.0",
|
|
18
|
+
"webdriver_manager>=4.0.2",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools]
|
|
22
|
+
packages = ["rcap_client"]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/mahdi-marjani/rcap-client"
|
|
26
|
+
Documentation = "https://github.com/mahdi-marjani/rcap-client"
|
|
27
|
+
Repository = "https://github.com/mahdi-marjani/rcap-client.git"
|
|
28
|
+
Issues = "https://github.com/mahdi-marjani/rcap-client/issues"
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import base64
|
|
3
|
+
import requests
|
|
4
|
+
from PIL import Image
|
|
5
|
+
|
|
6
|
+
SERVER_URL = "http://localhost:8000"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get_models():
|
|
10
|
+
res = requests.get(f"{SERVER_URL}/models")
|
|
11
|
+
res.raise_for_status()
|
|
12
|
+
return res.json()["models"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def detect_cells(image_array, grid, target_text):
|
|
16
|
+
image = Image.fromarray(image_array)
|
|
17
|
+
buffer = io.BytesIO()
|
|
18
|
+
image.save(buffer, format="PNG")
|
|
19
|
+
|
|
20
|
+
image_b64 = base64.b64encode(buffer.getvalue()).decode()
|
|
21
|
+
|
|
22
|
+
res = requests.post(
|
|
23
|
+
f"{SERVER_URL}/detect",
|
|
24
|
+
json={
|
|
25
|
+
"image": image_b64,
|
|
26
|
+
"grid": grid, # "3x3" or "4x4"
|
|
27
|
+
"target": target_text,
|
|
28
|
+
},
|
|
29
|
+
timeout=60,
|
|
30
|
+
)
|
|
31
|
+
res.raise_for_status()
|
|
32
|
+
return res.json()["cells"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from .solver import RecaptchaSolver
|
|
2
|
+
from selenium import webdriver
|
|
3
|
+
from selenium.webdriver.firefox.service import Service
|
|
4
|
+
from webdriver_manager.firefox import GeckoDriverManager
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if __name__ == "__main__":
|
|
8
|
+
driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))
|
|
9
|
+
driver.get("https://google.com/recaptcha/api2/demo")
|
|
10
|
+
|
|
11
|
+
solver = RecaptchaSolver(driver)
|
|
12
|
+
solver.solve()
|
|
13
|
+
|
|
14
|
+
print("reCAPTCHA solved!")
|
|
15
|
+
driver.quit()
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
from selenium.webdriver.common.by import By
|
|
2
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
|
3
|
+
from selenium.webdriver.support import expected_conditions as EC
|
|
4
|
+
|
|
5
|
+
from .utils import (
|
|
6
|
+
switch_to_recaptcha_frame,
|
|
7
|
+
get_all_image_urls,
|
|
8
|
+
get_image_array,
|
|
9
|
+
get_new_dynamic_image_urls,
|
|
10
|
+
paste_image_on_main,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from .api import get_models, detect_cells
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BaseRecaptchaSolver:
|
|
17
|
+
def __init__(self, driver):
|
|
18
|
+
self.driver = driver
|
|
19
|
+
|
|
20
|
+
# =========================
|
|
21
|
+
# Abstract methods (override in subclasses)
|
|
22
|
+
# =========================
|
|
23
|
+
|
|
24
|
+
def is_model_available(self, target_text):
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
def detect(self, image_array, grid, target_text):
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
# =========================
|
|
31
|
+
# Public API
|
|
32
|
+
# =========================
|
|
33
|
+
|
|
34
|
+
def solve(self):
|
|
35
|
+
self._click_checkbox()
|
|
36
|
+
self._solve_challenge()
|
|
37
|
+
|
|
38
|
+
# =========================
|
|
39
|
+
# High-level flow
|
|
40
|
+
# =========================
|
|
41
|
+
|
|
42
|
+
def _solve_challenge(self):
|
|
43
|
+
while True:
|
|
44
|
+
try:
|
|
45
|
+
solved = self._wait_until_challenge_ready_or_solved()
|
|
46
|
+
if solved:
|
|
47
|
+
self._finalize()
|
|
48
|
+
break
|
|
49
|
+
|
|
50
|
+
captcha_type, target_text, answers, main_image_array = self._analyze_challenge()
|
|
51
|
+
|
|
52
|
+
if captcha_type is None:
|
|
53
|
+
self._reload()
|
|
54
|
+
continue
|
|
55
|
+
|
|
56
|
+
if captcha_type == "dynamic":
|
|
57
|
+
self._solve_dynamic(target_text, answers, main_image_array)
|
|
58
|
+
else:
|
|
59
|
+
self._click_answers(answers)
|
|
60
|
+
|
|
61
|
+
if self._verify():
|
|
62
|
+
self._finalize()
|
|
63
|
+
break
|
|
64
|
+
|
|
65
|
+
except Exception as e:
|
|
66
|
+
print(e)
|
|
67
|
+
self._recover_from_error()
|
|
68
|
+
|
|
69
|
+
# =========================
|
|
70
|
+
# Initial checkbox
|
|
71
|
+
# =========================
|
|
72
|
+
|
|
73
|
+
def _click_checkbox(self):
|
|
74
|
+
switch_to_recaptcha_frame(self.driver, '//iframe[@title="reCAPTCHA"]')
|
|
75
|
+
WebDriverWait(self.driver, 10).until(
|
|
76
|
+
EC.element_to_be_clickable(
|
|
77
|
+
(By.XPATH, '//div[@class="recaptcha-checkbox-border"]')
|
|
78
|
+
)
|
|
79
|
+
).click()
|
|
80
|
+
self._switch_to_challenge_frame()
|
|
81
|
+
|
|
82
|
+
# =========================
|
|
83
|
+
# Challenge state handling
|
|
84
|
+
# =========================
|
|
85
|
+
|
|
86
|
+
def _wait_until_challenge_ready_or_solved(self):
|
|
87
|
+
for _ in range(200):
|
|
88
|
+
try:
|
|
89
|
+
self._switch_to_challenge_frame()
|
|
90
|
+
WebDriverWait(self.driver, 0.1).until(
|
|
91
|
+
EC.element_to_be_clickable((By.ID, "recaptcha-reload-button"))
|
|
92
|
+
)
|
|
93
|
+
return False
|
|
94
|
+
except Exception:
|
|
95
|
+
if self._is_checkbox_checked():
|
|
96
|
+
return True
|
|
97
|
+
return False
|
|
98
|
+
|
|
99
|
+
def _analyze_challenge(self):
|
|
100
|
+
self._switch_to_challenge_frame()
|
|
101
|
+
|
|
102
|
+
reload_btn = WebDriverWait(self.driver, 10).until(
|
|
103
|
+
EC.element_to_be_clickable((By.ID, "recaptcha-reload-button"))
|
|
104
|
+
)
|
|
105
|
+
title_wrapper = WebDriverWait(self.driver, 10).until(
|
|
106
|
+
EC.presence_of_element_located((By.ID, "rc-imageselect"))
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
target_text = title_wrapper.find_element(By.XPATH, ".//strong").text
|
|
110
|
+
|
|
111
|
+
if not self.is_model_available(target_text):
|
|
112
|
+
return None, None, None, None
|
|
113
|
+
|
|
114
|
+
if "squares" in title_wrapper.text:
|
|
115
|
+
return self._handle_4x4(target_text)
|
|
116
|
+
|
|
117
|
+
if "none" in title_wrapper.text:
|
|
118
|
+
return self._handle_dynamic_3x3(target_text)
|
|
119
|
+
|
|
120
|
+
return self._handle_static_3x3(target_text)
|
|
121
|
+
|
|
122
|
+
# =========================
|
|
123
|
+
# CAPTCHA type handlers
|
|
124
|
+
# =========================
|
|
125
|
+
|
|
126
|
+
def _handle_4x4(self, target_text):
|
|
127
|
+
img_urls = get_all_image_urls(self.driver)
|
|
128
|
+
main_image_array = get_image_array(img_urls[0])
|
|
129
|
+
|
|
130
|
+
answers = self.detect(main_image_array, "4x4", target_text)
|
|
131
|
+
if 1 <= len(answers) < 16:
|
|
132
|
+
return "squares", target_text, answers, main_image_array
|
|
133
|
+
|
|
134
|
+
return None, None, None, None
|
|
135
|
+
|
|
136
|
+
def _handle_dynamic_3x3(self, target_text):
|
|
137
|
+
img_urls = get_all_image_urls(self.driver)
|
|
138
|
+
if len(set(img_urls)) != 1:
|
|
139
|
+
return None, None, None
|
|
140
|
+
|
|
141
|
+
main_image_array = get_image_array(img_urls[0])
|
|
142
|
+
answers = self.detect(main_image_array, "3x3", target_text)
|
|
143
|
+
|
|
144
|
+
if len(answers) > 2:
|
|
145
|
+
return "dynamic", target_text, answers, main_image_array
|
|
146
|
+
|
|
147
|
+
return None, None, None, None
|
|
148
|
+
|
|
149
|
+
def _handle_static_3x3(self, target_text):
|
|
150
|
+
img_urls = get_all_image_urls(self.driver)
|
|
151
|
+
main_image_array = get_image_array(img_urls[0])
|
|
152
|
+
|
|
153
|
+
answers = self.detect(main_image_array, "3x3", target_text)
|
|
154
|
+
if len(answers) > 2:
|
|
155
|
+
return "selection", target_text, answers, main_image_array
|
|
156
|
+
|
|
157
|
+
return None, None, None, None
|
|
158
|
+
|
|
159
|
+
# =========================
|
|
160
|
+
# Solvers
|
|
161
|
+
# =========================
|
|
162
|
+
|
|
163
|
+
def _solve_dynamic(self, target_text, answers, main_image_array):
|
|
164
|
+
self._click_answers(answers)
|
|
165
|
+
|
|
166
|
+
while True:
|
|
167
|
+
old_urls = get_all_image_urls(self.driver)
|
|
168
|
+
is_new, new_urls = self._wait_for_new_dynamic_images(
|
|
169
|
+
answers, old_urls
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
new_images_array = self._download_dynamic_images(answers, new_urls)
|
|
173
|
+
main_image_array = self._merge_dynamic_images(answers, main_image_array, new_images_array)
|
|
174
|
+
|
|
175
|
+
answers = self.detect(main_image_array, "3x3", target_text)
|
|
176
|
+
if not answers:
|
|
177
|
+
break
|
|
178
|
+
|
|
179
|
+
self._click_answers(answers)
|
|
180
|
+
|
|
181
|
+
# =========================
|
|
182
|
+
# Actions
|
|
183
|
+
# =========================
|
|
184
|
+
|
|
185
|
+
def _click_answers(self, answers):
|
|
186
|
+
for answer in answers:
|
|
187
|
+
WebDriverWait(self.driver, 10).until(
|
|
188
|
+
EC.element_to_be_clickable(
|
|
189
|
+
(
|
|
190
|
+
By.XPATH,
|
|
191
|
+
f'(//div[@id="rc-imageselect-target"]//td)[{answer}]',
|
|
192
|
+
)
|
|
193
|
+
)
|
|
194
|
+
).click()
|
|
195
|
+
|
|
196
|
+
def _verify(self):
|
|
197
|
+
verify = WebDriverWait(self.driver, 10).until(
|
|
198
|
+
EC.element_to_be_clickable((By.ID, "recaptcha-verify-button"))
|
|
199
|
+
)
|
|
200
|
+
verify.click()
|
|
201
|
+
|
|
202
|
+
for _ in range(200):
|
|
203
|
+
try:
|
|
204
|
+
self._switch_to_challenge_frame()
|
|
205
|
+
WebDriverWait(self.driver, 0.1).until(
|
|
206
|
+
EC.presence_of_element_located(
|
|
207
|
+
(
|
|
208
|
+
By.XPATH,
|
|
209
|
+
'//button[@id="recaptcha-verify-button" and not(contains(@class, "rc-button-default-disabled"))]',
|
|
210
|
+
)
|
|
211
|
+
)
|
|
212
|
+
)
|
|
213
|
+
return False
|
|
214
|
+
except Exception:
|
|
215
|
+
if self._is_checkbox_checked():
|
|
216
|
+
return True
|
|
217
|
+
|
|
218
|
+
return False
|
|
219
|
+
|
|
220
|
+
# =========================
|
|
221
|
+
# Dynamic helpers
|
|
222
|
+
# =========================
|
|
223
|
+
|
|
224
|
+
def _wait_for_new_dynamic_images(self, answers, old_urls):
|
|
225
|
+
while True:
|
|
226
|
+
is_new, new_urls = get_new_dynamic_image_urls(
|
|
227
|
+
answers, old_urls, self.driver
|
|
228
|
+
)
|
|
229
|
+
if is_new:
|
|
230
|
+
return is_new, new_urls
|
|
231
|
+
|
|
232
|
+
def _download_dynamic_images(self, answers, img_urls):
|
|
233
|
+
new_images_array = {}
|
|
234
|
+
for answer in answers:
|
|
235
|
+
idx = answer - 1
|
|
236
|
+
new_images_array[answer] = get_image_array(img_urls[idx])
|
|
237
|
+
|
|
238
|
+
return new_images_array
|
|
239
|
+
|
|
240
|
+
def _merge_dynamic_images(self, answers, main_image_array, new_images_array):
|
|
241
|
+
while True:
|
|
242
|
+
try:
|
|
243
|
+
for answer in answers:
|
|
244
|
+
new_image_array = new_images_array[answer]
|
|
245
|
+
main_image_array = paste_image_on_main(main_image_array, new_image_array, answer)
|
|
246
|
+
return main_image_array
|
|
247
|
+
except Exception:
|
|
248
|
+
continue
|
|
249
|
+
|
|
250
|
+
# =========================
|
|
251
|
+
# Frame / state utils
|
|
252
|
+
# =========================
|
|
253
|
+
|
|
254
|
+
def _switch_to_challenge_frame(self):
|
|
255
|
+
switch_to_recaptcha_frame(
|
|
256
|
+
self.driver,
|
|
257
|
+
'//iframe[contains(@title, "challenge") and contains(@title, "recaptcha")]',
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
def _is_checkbox_checked(self):
|
|
261
|
+
switch_to_recaptcha_frame(self.driver, '//iframe[@title="reCAPTCHA"]')
|
|
262
|
+
return (
|
|
263
|
+
WebDriverWait(self.driver, 10)
|
|
264
|
+
.until(
|
|
265
|
+
EC.presence_of_element_located(
|
|
266
|
+
(By.XPATH, '//span[@id="recaptcha-anchor"]')
|
|
267
|
+
)
|
|
268
|
+
)
|
|
269
|
+
.get_attribute("aria-checked")
|
|
270
|
+
== "true"
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
def _reload(self):
|
|
274
|
+
self._switch_to_challenge_frame()
|
|
275
|
+
WebDriverWait(self.driver, 10).until(
|
|
276
|
+
EC.element_to_be_clickable((By.ID, "recaptcha-reload-button"))
|
|
277
|
+
).click()
|
|
278
|
+
|
|
279
|
+
def _recover_from_error(self):
|
|
280
|
+
try:
|
|
281
|
+
self._click_checkbox()
|
|
282
|
+
except Exception:
|
|
283
|
+
pass
|
|
284
|
+
|
|
285
|
+
def _finalize(self):
|
|
286
|
+
self.driver.switch_to.default_content()
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
class RecaptchaSolver(BaseRecaptchaSolver):
|
|
290
|
+
def __init__(self, driver):
|
|
291
|
+
super().__init__(driver)
|
|
292
|
+
self.available_models = get_models()
|
|
293
|
+
|
|
294
|
+
def is_model_available(self, target_text):
|
|
295
|
+
target_text = target_text.lower()
|
|
296
|
+
return any(model in target_text for model in self.available_models)
|
|
297
|
+
|
|
298
|
+
def detect(self, image_array, grid, target_text):
|
|
299
|
+
return detect_cells(image_array, grid, target_text)
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import requests
|
|
3
|
+
import numpy as np
|
|
4
|
+
from PIL import Image
|
|
5
|
+
from selenium.webdriver.common.by import By
|
|
6
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
|
7
|
+
from selenium.webdriver.support import expected_conditions as EC
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def switch_to_recaptcha_frame(driver, frame_xpath):
|
|
11
|
+
"""Switch to the reCAPTCHA frame."""
|
|
12
|
+
driver.switch_to.default_content()
|
|
13
|
+
frame = WebDriverWait(driver, 10).until(
|
|
14
|
+
EC.presence_of_element_located((By.XPATH, frame_xpath))
|
|
15
|
+
)
|
|
16
|
+
driver.switch_to.frame(frame)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_image_array(url):
|
|
20
|
+
"""Download an image from URL and return it as a numpy array."""
|
|
21
|
+
response = requests.get(url)
|
|
22
|
+
if response.status_code == 200:
|
|
23
|
+
image = Image.open(io.BytesIO(response.content))
|
|
24
|
+
return np.array(image)
|
|
25
|
+
else:
|
|
26
|
+
raise ValueError(f"Failed to download image from {url}")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def paste_image_on_main(main_img, new_img, position):
|
|
30
|
+
"""Paste a new image onto the main one at a position.
|
|
31
|
+
|
|
32
|
+
Positions map to a 3x3 grid like this:
|
|
33
|
+
+---+---+---+
|
|
34
|
+
| 1 | 2 | 3 |
|
|
35
|
+
+---+---+---+
|
|
36
|
+
| 4 | 5 | 6 |
|
|
37
|
+
+---+---+---+
|
|
38
|
+
| 7 | 8 | 9 |
|
|
39
|
+
+---+---+---+
|
|
40
|
+
"""
|
|
41
|
+
main = np.copy(main_img)
|
|
42
|
+
|
|
43
|
+
section_map = {
|
|
44
|
+
1: (0, 0),
|
|
45
|
+
2: (0, 1),
|
|
46
|
+
3: (0, 2),
|
|
47
|
+
4: (1, 0),
|
|
48
|
+
5: (1, 1),
|
|
49
|
+
6: (1, 2),
|
|
50
|
+
7: (2, 0),
|
|
51
|
+
8: (2, 1),
|
|
52
|
+
9: (2, 2),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
row, col = section_map[position]
|
|
56
|
+
height, width = main.shape[0] // 3, main.shape[1] // 3
|
|
57
|
+
|
|
58
|
+
start_row = row * height
|
|
59
|
+
start_col = col * width
|
|
60
|
+
|
|
61
|
+
main[start_row : start_row + height, start_col : start_col + width] = new_img
|
|
62
|
+
|
|
63
|
+
return main
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def get_all_image_urls(driver):
|
|
67
|
+
"""Get all image URLs from the CAPTCHA grid."""
|
|
68
|
+
images = WebDriverWait(driver, 10).until(
|
|
69
|
+
EC.presence_of_all_elements_located(
|
|
70
|
+
(By.XPATH, '//div[@id="rc-imageselect-target"]//img')
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
return [img.get_attribute("src") for img in images]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def get_new_dynamic_image_urls(answers, old_urls, driver):
|
|
77
|
+
"""Check for new dynamic CAPTCHA images and return if changed."""
|
|
78
|
+
images = WebDriverWait(driver, 10).until(
|
|
79
|
+
EC.presence_of_all_elements_located(
|
|
80
|
+
(By.XPATH, '//div[@id="rc-imageselect-target"]//img')
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
new_urls = []
|
|
84
|
+
|
|
85
|
+
for img in images:
|
|
86
|
+
try:
|
|
87
|
+
new_urls.append(img.get_attribute("src"))
|
|
88
|
+
except:
|
|
89
|
+
is_new = False
|
|
90
|
+
return is_new, new_urls
|
|
91
|
+
|
|
92
|
+
same_count = 0
|
|
93
|
+
for answer in answers:
|
|
94
|
+
if new_urls[answer - 1] == old_urls[answer - 1]:
|
|
95
|
+
same_count += 1
|
|
96
|
+
|
|
97
|
+
if same_count > 0:
|
|
98
|
+
is_new = False
|
|
99
|
+
return is_new, new_urls
|
|
100
|
+
else:
|
|
101
|
+
is_new = True
|
|
102
|
+
return is_new, new_urls
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rcap-client
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: rcap client for solving reCAPTCHA challenges.
|
|
5
|
+
Author-email: Mahdi Marjani <mahdi.marjani.dev@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mahdi-marjani/rcap-client
|
|
8
|
+
Project-URL: Documentation, https://github.com/mahdi-marjani/rcap-client
|
|
9
|
+
Project-URL: Repository, https://github.com/mahdi-marjani/rcap-client.git
|
|
10
|
+
Project-URL: Issues, https://github.com/mahdi-marjani/rcap-client/issues
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy>=2.2.6
|
|
15
|
+
Requires-Dist: Pillow>=12.1.0
|
|
16
|
+
Requires-Dist: Requests>=2.32.5
|
|
17
|
+
Requires-Dist: selenium>=4.39.0
|
|
18
|
+
Requires-Dist: webdriver_manager>=4.0.2
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# rcap-client
|
|
22
|
+
|
|
23
|
+
rcap client for solving reCAPTCHA using Selenium and rcap server.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
Install via pip:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
pip install rcap-client
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Here's an example of how to use it:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from selenium import webdriver
|
|
39
|
+
from selenium.webdriver.firefox.service import Service
|
|
40
|
+
from webdriver_manager.firefox import GeckoDriverManager
|
|
41
|
+
from rcap_client.solver import RecaptchaSolver
|
|
42
|
+
|
|
43
|
+
driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))
|
|
44
|
+
driver.get("https://www.google.com/recaptcha/api2/demo")
|
|
45
|
+
|
|
46
|
+
solver = RecaptchaSolver(driver)
|
|
47
|
+
solver.solve() # Done!
|
|
48
|
+
|
|
49
|
+
print("reCAPTCHA solved!")
|
|
50
|
+
input("Press Enter to quit...")
|
|
51
|
+
driver.quit()
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Details
|
|
55
|
+
|
|
56
|
+
- Uses Selenium for browser interaction.
|
|
57
|
+
- Relies on a local API (localhost:8000) for image detection.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
rcap_client/__init__.py
|
|
5
|
+
rcap_client/api.py
|
|
6
|
+
rcap_client/example.py
|
|
7
|
+
rcap_client/solver.py
|
|
8
|
+
rcap_client/utils.py
|
|
9
|
+
rcap_client.egg-info/PKG-INFO
|
|
10
|
+
rcap_client.egg-info/SOURCES.txt
|
|
11
|
+
rcap_client.egg-info/dependency_links.txt
|
|
12
|
+
rcap_client.egg-info/requires.txt
|
|
13
|
+
rcap_client.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rcap_client
|