zhou12189108 commited on
Commit
0d3cc7b
1 Parent(s): 0114a7e

Update hcaptcha_solver.py

Browse files
Files changed (1) hide show
  1. hcaptcha_solver.py +28 -24
hcaptcha_solver.py CHANGED
@@ -124,30 +124,34 @@ async def on_response(response, page):
124
 
125
 
126
  async def classify_click(page, data, round0, examples):
127
- await page.wait_for_selector("//iframe[contains(@title, 'hCaptcha challenge')]")
128
- frame_challenge = page.frame_locator("//iframe[contains(@title, 'hCaptcha challenge')]")
129
- samples = frame_challenge.locator("//div[@class='task-image']")
130
- await frame_challenge.locator("//div[@tabindex='0']").nth(0).wait_for()
131
- count = await samples.count()
132
- print(count)
133
- clicks = nopecha.Recognition.solve(
134
- type='hcaptcha',
135
- task=data.get("requester_question").get("en"),
136
- image_urls=[data.get("tasklist")[i]["datapoint_uri"] for i in (range(9) if round0 == 0 else range(9, 18))],
137
- image_examples=examples
138
- )
139
- for i in range(count):
140
- sample = samples.nth(i)
141
- await sample.wait_for()
142
- if clicks[i]:
143
- print("try to click")
144
- await sample.click(delay=200)
145
- print(clicks)
146
- await asyncio.sleep(random.uniform(0.1, 0.3))
147
- fl = frame_challenge.locator("//div[@class='button-submit button']")
148
- await fl.click()
149
- if round0 == 0:
150
- await classify_click(page, data, 1, examples)
 
 
 
 
151
 
152
 
153
  async def area_click(page, data, round0, examples):
 
124
 
125
 
126
  async def classify_click(page, data, round0, examples):
127
+ try:
128
+ await page.wait_for_selector("//iframe[contains(@title, 'hCaptcha challenge')]")
129
+ frame_challenge = page.frame_locator("//iframe[contains(@title, 'hCaptcha challenge')]")
130
+ samples = frame_challenge.locator("//div[@class='task-image']")
131
+ await frame_challenge.locator("//div[@tabindex='0']").nth(0).wait_for()
132
+ count = await samples.count()
133
+ print(count)
134
+ clicks = nopecha.Recognition.solve(
135
+ type='hcaptcha',
136
+ task=data.get("requester_question").get("en"),
137
+ image_urls=[data.get("tasklist")[i]["datapoint_uri"] for i in (range(9) if round0 == 0 else range(9, 18))],
138
+ image_examples=examples
139
+ )
140
+ for i in range(count):
141
+ sample = samples.nth(i)
142
+ await sample.wait_for()
143
+ if clicks[i]:
144
+ print("try to click")
145
+ await sample.click(delay=200)
146
+ print(clicks)
147
+ await asyncio.sleep(random.uniform(0.1, 0.3))
148
+ fl = frame_challenge.locator("//div[@class='button-submit button']")
149
+ await fl.click()
150
+ if round0 == 0:
151
+ await classify_click(page, data, 1, examples)
152
+ except Exception as e:
153
+ print(e)
154
+ await classify_click(page, data, round0, examples)
155
 
156
 
157
  async def area_click(page, data, round0, examples):