Spaces:
Running
Running
Commit
·
12f8b09
1
Parent(s):
6e19150
Upload 2 files
Browse files- api.py +7 -2
- hcaptcha_solver.py +9 -4
api.py
CHANGED
@@ -2,6 +2,7 @@ import hashlib
|
|
2 |
import os
|
3 |
import asyncio
|
4 |
import uuid
|
|
|
5 |
from flask import Flask, jsonify, request, logging as flog
|
6 |
from flask_limiter.util import get_remote_address
|
7 |
import hcaptcha_solver
|
@@ -79,7 +80,11 @@ def solver_captcha():
|
|
79 |
data = request.get_json(force=True, silent=True)
|
80 |
if not check_request(require_data, data):
|
81 |
return jsonify(msg="Unauthorized Request"), 403
|
82 |
-
|
|
|
|
|
|
|
|
|
83 |
|
84 |
|
85 |
@app.route("/api/update", methods=["POST"])
|
@@ -92,4 +97,4 @@ def update_model():
|
|
92 |
return jsonify(statue="ok"), 200
|
93 |
|
94 |
|
95 |
-
app.run(host="0.0.0.0", port=
|
|
|
2 |
import os
|
3 |
import asyncio
|
4 |
import uuid
|
5 |
+
import shutil
|
6 |
from flask import Flask, jsonify, request, logging as flog
|
7 |
from flask_limiter.util import get_remote_address
|
8 |
import hcaptcha_solver
|
|
|
80 |
data = request.get_json(force=True, silent=True)
|
81 |
if not check_request(require_data, data):
|
82 |
return jsonify(msg="Unauthorized Request"), 403
|
83 |
+
dir_path=generate_uuid()
|
84 |
+
resp=asyncio.run(hcaptcha_solver.bytedance(data["host"], data["site_key"], dir_path))
|
85 |
+
shutil.rmtree(dir_path)
|
86 |
+
shutil.rmtree("tmp_dir")
|
87 |
+
return resp
|
88 |
|
89 |
|
90 |
@app.route("/api/update", methods=["POST"])
|
|
|
97 |
return jsonify(statue="ok"), 200
|
98 |
|
99 |
|
100 |
+
app.run(host="0.0.0.0", port=8081)
|
hcaptcha_solver.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from pathlib import Path
|
2 |
-
|
|
|
3 |
from loguru import logger
|
4 |
from playwright.async_api import BrowserContext as ASyncContext, async_playwright
|
5 |
import hcaptcha_challenger as solver
|
@@ -17,7 +18,7 @@ tmp_dir = Path(__file__).parent.joinpath("tmp_dir")
|
|
17 |
async def hit_challenge(context: ASyncContext, host, sitekey, user_data_dir, times: int = 8):
|
18 |
await context.route('**/*', lambda route, request: route_continuation(route, request, host, sitekey))
|
19 |
page = context.pages[0]
|
20 |
-
agent = AgentT.from_page(page=page, tmp_dir=tmp_dir)
|
21 |
await page.goto(f"https://{host}")
|
22 |
|
23 |
await agent.handle_checkbox()
|
@@ -32,8 +33,7 @@ async def hit_challenge(context: ASyncContext, host, sitekey, user_data_dir, tim
|
|
32 |
await fl.locator("//div[@class='refresh button']").click()
|
33 |
case agent.status.CHALLENGE_SUCCESS:
|
34 |
rqdata = agent.cr.__dict__
|
35 |
-
|
36 |
-
print(os.system(f"rm -rf {user_data_dir}"))
|
37 |
return rqdata["generated_pass_UUID"]
|
38 |
|
39 |
|
@@ -105,6 +105,7 @@ async def route_continuation(route, request, host, sitekey):
|
|
105 |
|
106 |
|
107 |
async def bytedance(host, sitekey, user_data_dirs):
|
|
|
108 |
# playwright install firefox --with-deps
|
109 |
try:
|
110 |
async with async_playwright() as p:
|
@@ -117,5 +118,9 @@ async def bytedance(host, sitekey, user_data_dirs):
|
|
117 |
token = await hit_challenge(context, host, sitekey, Path(__file__).parent.joinpath(user_data_dirs))
|
118 |
return token
|
119 |
except Exception as e:
|
|
|
|
|
120 |
print(e)
|
|
|
|
|
121 |
|
|
|
1 |
from pathlib import Path
|
2 |
+
|
3 |
+
import traceback
|
4 |
from loguru import logger
|
5 |
from playwright.async_api import BrowserContext as ASyncContext, async_playwright
|
6 |
import hcaptcha_challenger as solver
|
|
|
18 |
async def hit_challenge(context: ASyncContext, host, sitekey, user_data_dir, times: int = 8):
|
19 |
await context.route('**/*', lambda route, request: route_continuation(route, request, host, sitekey))
|
20 |
page = context.pages[0]
|
21 |
+
agent = AgentT.from_page(page=page, tmp_dir=tmp_dir,self_supervised=True)
|
22 |
await page.goto(f"https://{host}")
|
23 |
|
24 |
await agent.handle_checkbox()
|
|
|
33 |
await fl.locator("//div[@class='refresh button']").click()
|
34 |
case agent.status.CHALLENGE_SUCCESS:
|
35 |
rqdata = agent.cr.__dict__
|
36 |
+
await context.close()
|
|
|
37 |
return rqdata["generated_pass_UUID"]
|
38 |
|
39 |
|
|
|
105 |
|
106 |
|
107 |
async def bytedance(host, sitekey, user_data_dirs):
|
108 |
+
print(user_data_dirs)
|
109 |
# playwright install firefox --with-deps
|
110 |
try:
|
111 |
async with async_playwright() as p:
|
|
|
118 |
token = await hit_challenge(context, host, sitekey, Path(__file__).parent.joinpath(user_data_dirs))
|
119 |
return token
|
120 |
except Exception as e:
|
121 |
+
await context.close()
|
122 |
+
traceback.print_exc()
|
123 |
print(e)
|
124 |
+
return traceback.format_exc()
|
125 |
+
|
126 |
|