auto-captcha 0.1.0__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.
- auto_captcha-0.1.0/LICENSE +21 -0
- auto_captcha-0.1.0/PKG-INFO +170 -0
- auto_captcha-0.1.0/README.md +140 -0
- auto_captcha-0.1.0/pyproject.toml +45 -0
- auto_captcha-0.1.0/setup.cfg +4 -0
- auto_captcha-0.1.0/src/auto_captcha/__init__.py +7 -0
- auto_captcha-0.1.0/src/auto_captcha/cli.py +96 -0
- auto_captcha-0.1.0/src/auto_captcha/mcp_server.py +230 -0
- auto_captcha-0.1.0/src/auto_captcha/solver.py +301 -0
- auto_captcha-0.1.0/src/auto_captcha/wrapper.py +151 -0
- auto_captcha-0.1.0/src/auto_captcha.egg-info/PKG-INFO +170 -0
- auto_captcha-0.1.0/src/auto_captcha.egg-info/SOURCES.txt +14 -0
- auto_captcha-0.1.0/src/auto_captcha.egg-info/dependency_links.txt +1 -0
- auto_captcha-0.1.0/src/auto_captcha.egg-info/entry_points.txt +2 -0
- auto_captcha-0.1.0/src/auto_captcha.egg-info/requires.txt +7 -0
- auto_captcha-0.1.0/src/auto_captcha.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Suhaas Chitturi
|
|
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,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: auto-captcha
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Universal captcha solver for Playwright automation — hCaptcha + reCAPTCHA v2 via NopeCHA API
|
|
5
|
+
Author: Suhaas Chitturi
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/interfluve-wav/auto-captcha
|
|
8
|
+
Project-URL: Repository, https://github.com/interfluve-wav/auto-captcha
|
|
9
|
+
Project-URL: Issues, https://github.com/interfluve-wav/auto-captcha/issues
|
|
10
|
+
Keywords: captcha,hcaptcha,recaptcha,playwright,automation,browser,solver
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Testing
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: requests>=2.28.0
|
|
25
|
+
Provides-Extra: playwright
|
|
26
|
+
Requires-Dist: playwright>=1.30.0; extra == "playwright"
|
|
27
|
+
Provides-Extra: all
|
|
28
|
+
Requires-Dist: playwright>=1.30.0; extra == "all"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# auto-captcha
|
|
32
|
+
|
|
33
|
+
Universal captcha solver for Playwright browser automation. Detects hCaptcha and reCAPTCHA v2, solves them via the NopeCHA API, and injects tokens — so your scripts never get stuck.
|
|
34
|
+
|
|
35
|
+
Works as a **Python library**, **CLI tool**, **MCP server**, and **Hermes skill**.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install auto-captcha
|
|
41
|
+
python -m playwright install chromium
|
|
42
|
+
|
|
43
|
+
# Or from source
|
|
44
|
+
git clone https://github.com/interfluve-wav/auto-captcha.git
|
|
45
|
+
cd auto-captcha
|
|
46
|
+
pip install -e ".[all]"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick Start (1 line)
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from auto_captcha import smart_page
|
|
53
|
+
|
|
54
|
+
with smart_page(api_key="your-key") as page:
|
|
55
|
+
page.goto("https://protected-site.com")
|
|
56
|
+
page.fill("#email", "user@example.com")
|
|
57
|
+
page.click("#submit") # captcha auto-solved
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Three Ways to Use
|
|
61
|
+
|
|
62
|
+
### 1. `smart_page()` — Context Manager (easiest)
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from auto_captcha import smart_page
|
|
66
|
+
|
|
67
|
+
with smart_page(api_key="your-key") as page:
|
|
68
|
+
page.goto("https://example.com")
|
|
69
|
+
page.fill("#email", "user@test.com")
|
|
70
|
+
page.click("#submit")
|
|
71
|
+
print(page.captcha_log) # [{'type': 'hcaptcha', 'status': 'solved'}]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 2. `SmartPage` — Wrap Existing Browser
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from auto_captcha import SmartPage
|
|
78
|
+
from playwright.sync_api import sync_playwright
|
|
79
|
+
|
|
80
|
+
pw = sync_playwright().start()
|
|
81
|
+
browser = pw.chromium.launch(headless=True)
|
|
82
|
+
page = SmartPage(browser.new_page(), api_key="your-key")
|
|
83
|
+
|
|
84
|
+
page.goto("https://example.com")
|
|
85
|
+
page.fill("#input", "value")
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 3. `CaptchaSolver` — Full Control
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from auto_captcha import CaptchaSolver
|
|
92
|
+
|
|
93
|
+
solver = CaptchaSolver(api_key="your-key")
|
|
94
|
+
|
|
95
|
+
captchas = solver.detect(page) # [{'type': 'hcaptcha', 'sitekey': '...'}]
|
|
96
|
+
token = solver.solve("hcaptcha", sitekey, url) # CaptchaResult(success=True, token='...')
|
|
97
|
+
solver.inject(page, "hcaptcha", token)
|
|
98
|
+
results = solver.auto_solve(page) # detect + solve + inject
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## CLI
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Check credits
|
|
105
|
+
auto-captcha credits --key YOUR_KEY
|
|
106
|
+
|
|
107
|
+
# Detect captchas
|
|
108
|
+
auto-captcha detect --url https://example.com --key YOUR_KEY
|
|
109
|
+
|
|
110
|
+
# Solve captchas
|
|
111
|
+
auto-captcha solve --url https://example.com --key YOUR_KEY
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## MCP Server (for AI agents)
|
|
115
|
+
|
|
116
|
+
Works with Claude Code, OpenClaw, Cursor, and any MCP-compatible agent.
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Add to Claude Code
|
|
120
|
+
claude mcp add auto-captcha -- python -m auto_captcha.mcp_server
|
|
121
|
+
|
|
122
|
+
# Or configure in MCP config
|
|
123
|
+
{
|
|
124
|
+
"mcpServers": {
|
|
125
|
+
"auto-captcha": {
|
|
126
|
+
"command": "python",
|
|
127
|
+
"args": ["-m", "auto_captcha.mcp_server"],
|
|
128
|
+
"env": {"NOPECHA_API_KEY": "your-key"}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Provides three MCP tools:
|
|
135
|
+
- `captcha_detect` — detect captchas on a URL
|
|
136
|
+
- `captcha_solve` — detect and solve all captchas
|
|
137
|
+
- `captcha_credits` — check NopeCHA credit balance
|
|
138
|
+
|
|
139
|
+
## Hermes Skill
|
|
140
|
+
|
|
141
|
+
Copy the `hermes-skill/` directory to `~/.hermes/skills/auto-captcha/` and set `NOPECHA_API_KEY` in your `.env`.
|
|
142
|
+
|
|
143
|
+
## Supported Captcha Types
|
|
144
|
+
|
|
145
|
+
| Type | Detection | Speed | Reliability |
|
|
146
|
+
|------|-----------|-------|-------------|
|
|
147
|
+
| hCaptcha (checkbox) | iframe + DOM | 10-40s | High |
|
|
148
|
+
| hCaptcha (enterprise) | iframe + DOM | 10-40s | High |
|
|
149
|
+
| reCAPTCHA v2 | iframe + DOM | 60-120s+ | Medium (queue) |
|
|
150
|
+
|
|
151
|
+
**Not supported:** reCAPTCHA v3 (score-based, no challenge), Cloudflare Turnstile, FunCAPTCHA
|
|
152
|
+
|
|
153
|
+
## Pitfalls
|
|
154
|
+
|
|
155
|
+
- **reCAPTCHA queues are slow** — can take 60-120+ seconds during peak
|
|
156
|
+
- **Each solve costs 1 credit** — check with `solver.get_credits()`
|
|
157
|
+
- **Headless detection** — some sites block headless; use `headless=False`
|
|
158
|
+
- **Lazy-loaded captchas** — add `time.sleep()` after actions that might trigger them
|
|
159
|
+
|
|
160
|
+
## NopeCHA API Key
|
|
161
|
+
|
|
162
|
+
Get free credits at [nopecha.com](https://nopecha.com). Set as environment variable:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
export NOPECHA_API_KEY="your-key"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# auto-captcha
|
|
2
|
+
|
|
3
|
+
Universal captcha solver for Playwright browser automation. Detects hCaptcha and reCAPTCHA v2, solves them via the NopeCHA API, and injects tokens — so your scripts never get stuck.
|
|
4
|
+
|
|
5
|
+
Works as a **Python library**, **CLI tool**, **MCP server**, and **Hermes skill**.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install auto-captcha
|
|
11
|
+
python -m playwright install chromium
|
|
12
|
+
|
|
13
|
+
# Or from source
|
|
14
|
+
git clone https://github.com/interfluve-wav/auto-captcha.git
|
|
15
|
+
cd auto-captcha
|
|
16
|
+
pip install -e ".[all]"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start (1 line)
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from auto_captcha import smart_page
|
|
23
|
+
|
|
24
|
+
with smart_page(api_key="your-key") as page:
|
|
25
|
+
page.goto("https://protected-site.com")
|
|
26
|
+
page.fill("#email", "user@example.com")
|
|
27
|
+
page.click("#submit") # captcha auto-solved
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Three Ways to Use
|
|
31
|
+
|
|
32
|
+
### 1. `smart_page()` — Context Manager (easiest)
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from auto_captcha import smart_page
|
|
36
|
+
|
|
37
|
+
with smart_page(api_key="your-key") as page:
|
|
38
|
+
page.goto("https://example.com")
|
|
39
|
+
page.fill("#email", "user@test.com")
|
|
40
|
+
page.click("#submit")
|
|
41
|
+
print(page.captcha_log) # [{'type': 'hcaptcha', 'status': 'solved'}]
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 2. `SmartPage` — Wrap Existing Browser
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from auto_captcha import SmartPage
|
|
48
|
+
from playwright.sync_api import sync_playwright
|
|
49
|
+
|
|
50
|
+
pw = sync_playwright().start()
|
|
51
|
+
browser = pw.chromium.launch(headless=True)
|
|
52
|
+
page = SmartPage(browser.new_page(), api_key="your-key")
|
|
53
|
+
|
|
54
|
+
page.goto("https://example.com")
|
|
55
|
+
page.fill("#input", "value")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 3. `CaptchaSolver` — Full Control
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from auto_captcha import CaptchaSolver
|
|
62
|
+
|
|
63
|
+
solver = CaptchaSolver(api_key="your-key")
|
|
64
|
+
|
|
65
|
+
captchas = solver.detect(page) # [{'type': 'hcaptcha', 'sitekey': '...'}]
|
|
66
|
+
token = solver.solve("hcaptcha", sitekey, url) # CaptchaResult(success=True, token='...')
|
|
67
|
+
solver.inject(page, "hcaptcha", token)
|
|
68
|
+
results = solver.auto_solve(page) # detect + solve + inject
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## CLI
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Check credits
|
|
75
|
+
auto-captcha credits --key YOUR_KEY
|
|
76
|
+
|
|
77
|
+
# Detect captchas
|
|
78
|
+
auto-captcha detect --url https://example.com --key YOUR_KEY
|
|
79
|
+
|
|
80
|
+
# Solve captchas
|
|
81
|
+
auto-captcha solve --url https://example.com --key YOUR_KEY
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## MCP Server (for AI agents)
|
|
85
|
+
|
|
86
|
+
Works with Claude Code, OpenClaw, Cursor, and any MCP-compatible agent.
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Add to Claude Code
|
|
90
|
+
claude mcp add auto-captcha -- python -m auto_captcha.mcp_server
|
|
91
|
+
|
|
92
|
+
# Or configure in MCP config
|
|
93
|
+
{
|
|
94
|
+
"mcpServers": {
|
|
95
|
+
"auto-captcha": {
|
|
96
|
+
"command": "python",
|
|
97
|
+
"args": ["-m", "auto_captcha.mcp_server"],
|
|
98
|
+
"env": {"NOPECHA_API_KEY": "your-key"}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Provides three MCP tools:
|
|
105
|
+
- `captcha_detect` — detect captchas on a URL
|
|
106
|
+
- `captcha_solve` — detect and solve all captchas
|
|
107
|
+
- `captcha_credits` — check NopeCHA credit balance
|
|
108
|
+
|
|
109
|
+
## Hermes Skill
|
|
110
|
+
|
|
111
|
+
Copy the `hermes-skill/` directory to `~/.hermes/skills/auto-captcha/` and set `NOPECHA_API_KEY` in your `.env`.
|
|
112
|
+
|
|
113
|
+
## Supported Captcha Types
|
|
114
|
+
|
|
115
|
+
| Type | Detection | Speed | Reliability |
|
|
116
|
+
|------|-----------|-------|-------------|
|
|
117
|
+
| hCaptcha (checkbox) | iframe + DOM | 10-40s | High |
|
|
118
|
+
| hCaptcha (enterprise) | iframe + DOM | 10-40s | High |
|
|
119
|
+
| reCAPTCHA v2 | iframe + DOM | 60-120s+ | Medium (queue) |
|
|
120
|
+
|
|
121
|
+
**Not supported:** reCAPTCHA v3 (score-based, no challenge), Cloudflare Turnstile, FunCAPTCHA
|
|
122
|
+
|
|
123
|
+
## Pitfalls
|
|
124
|
+
|
|
125
|
+
- **reCAPTCHA queues are slow** — can take 60-120+ seconds during peak
|
|
126
|
+
- **Each solve costs 1 credit** — check with `solver.get_credits()`
|
|
127
|
+
- **Headless detection** — some sites block headless; use `headless=False`
|
|
128
|
+
- **Lazy-loaded captchas** — add `time.sleep()` after actions that might trigger them
|
|
129
|
+
|
|
130
|
+
## NopeCHA API Key
|
|
131
|
+
|
|
132
|
+
Get free credits at [nopecha.com](https://nopecha.com). Set as environment variable:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
export NOPECHA_API_KEY="your-key"
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "auto-captcha"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Universal captcha solver for Playwright automation — hCaptcha + reCAPTCHA v2 via NopeCHA API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Suhaas Chitturi"},
|
|
14
|
+
]
|
|
15
|
+
keywords = ["captcha", "hcaptcha", "recaptcha", "playwright", "automation", "browser", "solver"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Topic :: Software Development :: Testing",
|
|
26
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"requests>=2.28.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
playwright = ["playwright>=1.30.0"]
|
|
34
|
+
all = ["playwright>=1.30.0"]
|
|
35
|
+
|
|
36
|
+
[project.scripts]
|
|
37
|
+
auto-captcha = "auto_captcha.cli:main"
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/interfluve-wav/auto-captcha"
|
|
41
|
+
Repository = "https://github.com/interfluve-wav/auto-captcha"
|
|
42
|
+
Issues = "https://github.com/interfluve-wav/auto-captcha/issues"
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.packages.find]
|
|
45
|
+
where = ["src"]
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""auto-captcha: Universal captcha solver for Playwright automation."""
|
|
2
|
+
|
|
3
|
+
from .solver import CaptchaSolver, CaptchaResult
|
|
4
|
+
from .wrapper import SmartPage, smart_page
|
|
5
|
+
|
|
6
|
+
__version__ = "0.1.0"
|
|
7
|
+
__all__ = ["CaptchaSolver", "CaptchaResult", "SmartPage", "smart_page"]
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
auto-captcha CLI — solve captchas from the command line.
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
auto-captcha solve --url https://example.com --key YOUR_KEY
|
|
7
|
+
auto-captcha credits --key YOUR_KEY
|
|
8
|
+
auto-captcha detect --url https://example.com --key YOUR_KEY
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
import time
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main():
|
|
19
|
+
parser = argparse.ArgumentParser(
|
|
20
|
+
prog="auto-captcha",
|
|
21
|
+
description="Universal captcha solver for Playwright automation",
|
|
22
|
+
)
|
|
23
|
+
sub = parser.add_subparsers(dest="command")
|
|
24
|
+
|
|
25
|
+
# -- solve --
|
|
26
|
+
solve_p = sub.add_parser("solve", help="Solve captchas on a URL")
|
|
27
|
+
solve_p.add_argument("--url", required=True, help="Page URL with captcha")
|
|
28
|
+
solve_p.add_argument("--key", default=os.environ.get("NOPECHA_API_KEY", ""), help="NopeCHA API key")
|
|
29
|
+
solve_p.add_argument("--headless", action="store_true", default=True)
|
|
30
|
+
solve_p.add_argument("--no-headless", action="store_false", dest="headless")
|
|
31
|
+
solve_p.add_argument("--timeout", type=float, default=120, help="Solve timeout in seconds")
|
|
32
|
+
|
|
33
|
+
# -- detect --
|
|
34
|
+
detect_p = sub.add_parser("detect", help="Detect captchas without solving")
|
|
35
|
+
detect_p.add_argument("--url", required=True, help="Page URL")
|
|
36
|
+
detect_p.add_argument("--key", default=os.environ.get("NOPECHA_API_KEY", ""), help="NopeCHA API key")
|
|
37
|
+
detect_p.add_argument("--headless", action="store_true", default=True)
|
|
38
|
+
|
|
39
|
+
# -- credits --
|
|
40
|
+
credits_p = sub.add_parser("credits", help="Check NopeCHA credit balance")
|
|
41
|
+
credits_p.add_argument("--key", default=os.environ.get("NOPECHA_API_KEY", ""), help="NopeCHA API key")
|
|
42
|
+
|
|
43
|
+
args = parser.parse_args()
|
|
44
|
+
|
|
45
|
+
if not args.command:
|
|
46
|
+
parser.print_help()
|
|
47
|
+
sys.exit(1)
|
|
48
|
+
|
|
49
|
+
if not args.key:
|
|
50
|
+
print("Error: NopeCHA API key required. Set NOPECHA_API_KEY or use --key", file=sys.stderr)
|
|
51
|
+
sys.exit(1)
|
|
52
|
+
|
|
53
|
+
from auto_captcha import CaptchaSolver
|
|
54
|
+
|
|
55
|
+
solver = CaptchaSolver(api_key=args.key)
|
|
56
|
+
|
|
57
|
+
if args.command == "credits":
|
|
58
|
+
credits = solver.get_credits()
|
|
59
|
+
print(json.dumps({"credits": credits}))
|
|
60
|
+
|
|
61
|
+
elif args.command == "detect":
|
|
62
|
+
from playwright.sync_api import sync_playwright
|
|
63
|
+
with sync_playwright() as p:
|
|
64
|
+
browser = p.chromium.launch(headless=args.headless, args=["--no-sandbox"])
|
|
65
|
+
page = browser.new_page()
|
|
66
|
+
page.goto(args.url, timeout=30000)
|
|
67
|
+
time.sleep(3)
|
|
68
|
+
captchas = solver.detect(page)
|
|
69
|
+
browser.close()
|
|
70
|
+
print(json.dumps(captchas, indent=2, default=str))
|
|
71
|
+
|
|
72
|
+
elif args.command == "solve":
|
|
73
|
+
from playwright.sync_api import sync_playwright
|
|
74
|
+
with sync_playwright() as p:
|
|
75
|
+
browser = p.chromium.launch(headless=args.headless, args=["--no-sandbox"])
|
|
76
|
+
page = browser.new_page()
|
|
77
|
+
page.goto(args.url, timeout=30000)
|
|
78
|
+
time.sleep(3)
|
|
79
|
+
results = solver.auto_solve(page)
|
|
80
|
+
browser.close()
|
|
81
|
+
|
|
82
|
+
output = []
|
|
83
|
+
for r in results:
|
|
84
|
+
output.append({
|
|
85
|
+
"type": r.captcha_type,
|
|
86
|
+
"success": r.success,
|
|
87
|
+
"token": r.token[:50] + "..." if len(r.token) > 50 else r.token,
|
|
88
|
+
"error": r.error,
|
|
89
|
+
"attempts": r.attempts,
|
|
90
|
+
"elapsed_sec": r.elapsed_sec,
|
|
91
|
+
})
|
|
92
|
+
print(json.dumps(output, indent=2))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == "__main__":
|
|
96
|
+
main()
|