zhou12189108 commited on
Commit
d172b0d
1 Parent(s): 2f414ac

Upload 2 files

Browse files
Files changed (2) hide show
  1. api.py +16 -1
  2. hcaptcha_solver.py +1 -11
api.py CHANGED
@@ -1,10 +1,25 @@
1
  import os
 
2
  import asyncio
3
  from flask import Flask, jsonify, request, logging as flog
4
  from flask_limiter.util import get_remote_address
 
 
5
  import hcaptcha_solver
6
 
7
  app = Flask(__name__)
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
 
10
  def get_ipaddr():
@@ -71,7 +86,7 @@ def solver_captcha():
71
  data = request.get_json(force=True, silent=True)
72
  if not check_request(require_data, data):
73
  return jsonify(msg="Unauthorized Request"), 403
74
- return asyncio.run(hcaptcha_solver.bytedance(data["host"], data["site_key"]))
75
 
76
 
77
  app.run(host="0.0.0.0", port=7860)
 
1
  import os
2
+ from pathlib import Path
3
  import asyncio
4
  from flask import Flask, jsonify, request, logging as flog
5
  from flask_limiter.util import get_remote_address
6
+ from playwright.async_api import async_playwright
7
+
8
  import hcaptcha_solver
9
 
10
  app = Flask(__name__)
11
+ user_data_dir = Path(__file__).parent.joinpath("user_data_dir")
12
+ context_dir = user_data_dir.joinpath("context")
13
+
14
+
15
+ async def __init__():
16
+ global contexts
17
+ async with async_playwright() as p:
18
+ contexts = p.firefox.launch_persistent_context(
19
+ user_data_dir=context_dir,
20
+ headless=True,
21
+ locale="en-US"
22
+ )
23
 
24
 
25
  def get_ipaddr():
 
86
  data = request.get_json(force=True, silent=True)
87
  if not check_request(require_data, data):
88
  return jsonify(msg="Unauthorized Request"), 403
89
+ return asyncio.run(hcaptcha_solver.bytedance(contexts, data["host"], data["site_key"]))
90
 
91
 
92
  app.run(host="0.0.0.0", port=7860)
hcaptcha_solver.py CHANGED
@@ -14,16 +14,6 @@ tmp_dir = Path(__file__).parent.joinpath("tmp_dir")
14
  contexts = None
15
 
16
 
17
- async def __init__():
18
- async with async_playwright() as p:
19
- global contexts
20
- contexts = p.firefox.launch_persistent_context(
21
- user_data_dir=context_dir,
22
- headless=True,
23
- locale="en-US"
24
- )
25
-
26
-
27
  async def hit_challenge(context: ASyncContext, host, sitekey, times: int = 8):
28
  await context.route('**/*', lambda route, request: route_continuation(route, request, host, sitekey))
29
  page = context.pages[0]
@@ -143,7 +133,7 @@ async def route_continuation(route, request, host, sitekey):
143
  await route.continue_()
144
 
145
 
146
- async def bytedance(host, sitekey):
147
  # playwright install firefox --with-deps
148
 
149
  await Malenia.apply_stealth(contexts)
 
14
  contexts = None
15
 
16
 
 
 
 
 
 
 
 
 
 
 
17
  async def hit_challenge(context: ASyncContext, host, sitekey, times: int = 8):
18
  await context.route('**/*', lambda route, request: route_continuation(route, request, host, sitekey))
19
  page = context.pages[0]
 
133
  await route.continue_()
134
 
135
 
136
+ async def bytedance(context, host, sitekey):
137
  # playwright install firefox --with-deps
138
 
139
  await Malenia.apply_stealth(contexts)