zhou12189108 commited on
Commit
e014353
1 Parent(s): bafbe94

Upload 2 files

Browse files
Files changed (2) hide show
  1. api.py +4 -2
  2. hcaptcha_solver.py +2 -7
api.py CHANGED
@@ -82,8 +82,10 @@ def solver_captcha():
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
 
 
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
+ if os.path.exists(dir_path):
86
+ shutil.rmtree(dir_path)
87
+ if os.path.exists("tmp_dir"):
88
+ shutil.rmtree("tmp_dir")
89
  return resp
90
 
91
 
hcaptcha_solver.py CHANGED
@@ -6,9 +6,8 @@ from playwright.async_api import BrowserContext as ASyncContext, async_playwrigh
6
  import hcaptcha_challenger as solver
7
  from hcaptcha_challenger.agents import AgentT, Malenia
8
 
9
-
10
  # Init local-side of the ModelHub
11
- solver.install(upgrade=True)
12
 
13
  # Save dataset to current working directory
14
  tmp_dir = Path(__file__).parent.joinpath("tmp_dir")
@@ -16,11 +15,9 @@ tmp_dir = Path(__file__).parent.joinpath("tmp_dir")
16
 
17
  @logger.catch
18
  async def hit_challenge(context: ASyncContext, host, sitekey, user_data_dir, times: int = 8):
19
- import hcaptcha_challenger as solver
20
- from hcaptcha_challenger.agents import AgentT, Malenia
21
  await context.route('**/*', lambda route, request: route_continuation(route, request, host, sitekey))
22
  page = context.pages[0]
23
- agent = AgentT.from_page(page=page, tmp_dir=tmp_dir,self_supervised=True)
24
  await page.goto(f"https://{host}")
25
 
26
  await agent.handle_checkbox()
@@ -124,5 +121,3 @@ async def bytedance(host, sitekey, user_data_dirs):
124
  traceback.print_exc()
125
  print(e)
126
  return traceback.format_exc()
127
-
128
-
 
6
  import hcaptcha_challenger as solver
7
  from hcaptcha_challenger.agents import AgentT, Malenia
8
 
 
9
  # Init local-side of the ModelHub
10
+ solver.install(upgrade=True, clip=True)
11
 
12
  # Save dataset to current working directory
13
  tmp_dir = Path(__file__).parent.joinpath("tmp_dir")
 
15
 
16
  @logger.catch
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, self_supervised=True)
21
  await page.goto(f"https://{host}")
22
 
23
  await agent.handle_checkbox()
 
121
  traceback.print_exc()
122
  print(e)
123
  return traceback.format_exc()