zhou12189108 commited on
Commit
bbb3d17
·
1 Parent(s): 842e9e1

Upload hcaptcha_solver.py

Browse files
Files changed (1) hide show
  1. hcaptcha_solver.py +3 -15
hcaptcha_solver.py CHANGED
@@ -1,6 +1,6 @@
1
  from pathlib import Path
2
  import os
3
- import requests
4
  from playwright.async_api import BrowserContext as ASyncContext, async_playwright
5
  import hcaptcha_challenger as solver
6
  from hcaptcha_challenger.agents import AgentT, Malenia
@@ -12,6 +12,7 @@ solver.install(upgrade=True)
12
  tmp_dir = Path(__file__).parent.joinpath("tmp_dir")
13
 
14
 
 
15
  async def hit_challenge(context: ASyncContext, host, sitekey, user_data_dir, times: int = 8):
16
  await context.route('**/*', lambda route, request: route_continuation(route, request, host, sitekey))
17
  page = context.pages[0]
@@ -59,21 +60,11 @@ async def route_continuation(route, request, host, sitekey):
59
  </style>
60
  </head>
61
  <body>
62
- <div aria-hidden="true" class="warning"><code>?hl=XXX</code> 使用它来更改 hl JS API 参数。</div>
63
- <div aria-hidden="true" class="warning"><code>?sitekey=XXX</code> 用它来更改站点密钥。</div>
64
- <div aria-hidden="true" class="warning"><code>?secret=XXX</code> 用它来更改站点验证秘密。</div>
65
- <div aria-hidden="true" class="warning"><code>?sitekey=XXX&secret=XXX</code> 用它来改变两者。</div>
66
  <br><br>
67
  <div class="sample-form">
68
  <form id="hcaptcha-demo-form" method="POST">
69
  <fieldset>
70
- <legend>带 hCAPTCHA 的示例表单</legend>
71
  <ul>
72
- <li role="presentation">
73
- <label for="ignored1" aria-hidden="true">表单字段(可选)</label>
74
- <input class="textinput" id="ignored1" name="email" type="text" tabindex="-1" aria-hidden="true" aria-label="表单字段(可选)" aria-required="false">
75
- </li>
76
- <li role="presentation">
77
  <div class>
78
 
79
  <div id="hcaptcha-demo" class="h-captcha" data-sitekey="%%%%%%%%%%%" data-callback="onSuccess" data-expired-callback="onExpire"></div>
@@ -100,10 +91,7 @@ async def route_continuation(route, request, host, sitekey):
100
  </script>
101
 
102
  </div>
103
- </li>
104
- <li>
105
  <input id="hcaptcha-demo-submit" type="submit" value="Submit">
106
- </li>
107
  </ul>
108
  </fieldset>
109
  </form>
@@ -141,5 +129,5 @@ async def bytedance(host, sitekey, user_data_dirs):
141
  locale="en-US"
142
  )
143
  await Malenia.apply_stealth(context)
144
- token = await hit_challenge(context, host, sitekey,Path(__file__).parent.joinpath(user_data_dirs))
145
  return token
 
1
  from pathlib import Path
2
  import os
3
+ from loguru import logger
4
  from playwright.async_api import BrowserContext as ASyncContext, async_playwright
5
  import hcaptcha_challenger as solver
6
  from hcaptcha_challenger.agents import AgentT, Malenia
 
12
  tmp_dir = Path(__file__).parent.joinpath("tmp_dir")
13
 
14
 
15
+ @logger.catch
16
  async def hit_challenge(context: ASyncContext, host, sitekey, user_data_dir, times: int = 8):
17
  await context.route('**/*', lambda route, request: route_continuation(route, request, host, sitekey))
18
  page = context.pages[0]
 
60
  </style>
61
  </head>
62
  <body>
 
 
 
 
63
  <br><br>
64
  <div class="sample-form">
65
  <form id="hcaptcha-demo-form" method="POST">
66
  <fieldset>
 
67
  <ul>
 
 
 
 
 
68
  <div class>
69
 
70
  <div id="hcaptcha-demo" class="h-captcha" data-sitekey="%%%%%%%%%%%" data-callback="onSuccess" data-expired-callback="onExpire"></div>
 
91
  </script>
92
 
93
  </div>
 
 
94
  <input id="hcaptcha-demo-submit" type="submit" value="Submit">
 
95
  </ul>
96
  </fieldset>
97
  </form>
 
129
  locale="en-US"
130
  )
131
  await Malenia.apply_stealth(context)
132
+ token = await hit_challenge(context, host, sitekey, Path(__file__).parent.joinpath(user_data_dirs))
133
  return token