Spaces:
Running
Running
Update hcaptcha_solver.py
Browse files- hcaptcha_solver.py +36 -32
hcaptcha_solver.py
CHANGED
@@ -155,38 +155,42 @@ async def classify_click(page, data, round0, examples):
|
|
155 |
|
156 |
|
157 |
async def area_click(page, data, round0, examples):
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
190 |
|
191 |
|
192 |
async def hit_challenge(context: ASyncContext, host, sitekey, times: int = 8):
|
|
|
155 |
|
156 |
|
157 |
async def area_click(page, data, round0, examples):
|
158 |
+
try:
|
159 |
+
await page.wait_for_selector("//iframe[contains(@title, 'hCaptcha challenge')]")
|
160 |
+
frame_challenge = page.frame_locator("//iframe[contains(@title, 'hCaptcha challenge')]")
|
161 |
+
locator = frame_challenge.locator("//div[@class='challenge-view']//canvas")
|
162 |
+
await locator.wait_for(state="visible")
|
163 |
+
image = await locator.screenshot()
|
164 |
+
if examples:
|
165 |
+
clicks = nopecha.Recognition.solve(
|
166 |
+
type='hcaptcha_area_select',
|
167 |
+
task=data.get("requester_question").get("en"),
|
168 |
+
image_data=[url_to_base64(data.get("tasklist")[0]["datapoint_uri"])],
|
169 |
+
image_examples=examples
|
170 |
+
)
|
171 |
+
else:
|
172 |
+
clicks = nopecha.Recognition.solve(
|
173 |
+
type='hcaptcha_area_select',
|
174 |
+
task=data.get("requester_question").get("en"),
|
175 |
+
image_data=[url_to_base64(data.get("tasklist")[0]["datapoint_uri"])]
|
176 |
+
)
|
177 |
+
print(clicks)
|
178 |
+
print(clicks["x"], clicks["y"])
|
179 |
+
print("try to click")
|
180 |
+
bounds = await locator.bounding_box()
|
181 |
+
print(bounds)
|
182 |
+
await locator.click(delay=200, position={"x": int(bounds["width"] * clicks["x"] / 100),
|
183 |
+
"y": int(bounds["height"] * clicks["y"] / 100)})
|
184 |
+
print("done")
|
185 |
+
|
186 |
+
fl = frame_challenge.locator("//div[@class='button-submit button']")
|
187 |
+
await fl.click()
|
188 |
+
await asyncio.sleep(random.uniform(0.1, 0.3))
|
189 |
+
if round0 == 0:
|
190 |
+
await area_click(page, data, 1, examples)
|
191 |
+
except Exception as e:
|
192 |
+
print(e)
|
193 |
+
await area_click(page, data, round0, examples)
|
194 |
|
195 |
|
196 |
async def hit_challenge(context: ASyncContext, host, sitekey, times: int = 8):
|