Spaces:
Running
Running
Upload hcaptcha_solver.py
Browse files- hcaptcha_solver.py +50 -46
hcaptcha_solver.py
CHANGED
@@ -94,49 +94,54 @@ def url_to_base64(url):
|
|
94 |
|
95 |
async def handle_response(page):
|
96 |
await asyncio.sleep(2)
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
else:
|
112 |
-
|
113 |
-
await
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
examples = url
|
120 |
-
task0 = frame_challenge.locator("//div[@class='task-image']")
|
121 |
-
await frame_challenge.locator("//div[@tabindex='0']").nth(0).wait_for()
|
122 |
-
count = await task0.count()
|
123 |
-
print(span_text)
|
124 |
-
print("done tasks for getting examples")
|
125 |
-
data = []
|
126 |
-
for i in range(count):
|
127 |
-
sample = task0.nth(i)
|
128 |
-
img = sample.locator('//div[@class="image"]')
|
129 |
-
style_attribute = await img.get_attribute("style")
|
130 |
-
url_match = re.search(r'url\("(.+?)"\)', style_attribute)
|
131 |
-
if url_match:
|
132 |
-
url = url_match.group(1)
|
133 |
-
data.append(url)
|
134 |
-
print("done tasks for getting url")
|
135 |
-
await classify_click(page, data, 0, examples, span_text)
|
136 |
-
else:
|
137 |
-
await asyncio.sleep(random.uniform(0.1, 0.3))
|
138 |
-
await frame_challenge.locator("//div[@class='refresh button']").click()
|
139 |
-
print("refresh")
|
140 |
|
141 |
|
142 |
async def on_response(response, page):
|
@@ -200,10 +205,10 @@ async def classify_click(page, data, round0, examples, quetsion0):
|
|
200 |
url = url_match.group(1)
|
201 |
data.append(url)
|
202 |
print("done tasks for getting url")
|
203 |
-
await classify_click(page, data, 1, examples,quetsion0)
|
204 |
except Exception as e:
|
205 |
print(e)
|
206 |
-
await classify_click(page, data, round0, examples,quetsion0)
|
207 |
|
208 |
|
209 |
async def area_click(page, data, round0, examples):
|
@@ -284,5 +289,4 @@ async def main(host, key):
|
|
284 |
print(e)
|
285 |
return token
|
286 |
|
287 |
-
|
288 |
-
#asyncio.run(main("free.vps.vc", "3bae0a5b-f2b8-43ef-98b7-76865a8a3997"))
|
|
|
94 |
|
95 |
async def handle_response(page):
|
96 |
await asyncio.sleep(2)
|
97 |
+
try:
|
98 |
+
await page.wait_for_selector("//iframe[contains(@title, 'hCaptcha challenge')]", timeout=15000)
|
99 |
+
frame_challenge = page.frame_locator("//iframe[contains(@title, 'hCaptcha challenge')]")
|
100 |
+
question_text = frame_challenge.locator("//div[@class='challenge-prompt']")
|
101 |
+
element_handle = await question_text.element_handle()
|
102 |
+
prompt_padding_element = await element_handle.query_selector("div.prompt-padding")
|
103 |
+
if prompt_padding_element is not None:
|
104 |
+
span_element = await element_handle.query_selector("h2 > span")
|
105 |
+
span_text = await span_element.inner_text()
|
106 |
+
examples0 = frame_challenge.locator('//div[@class="challenge-example"]')
|
107 |
+
examples = examples0.locator('div.image[aria-hidden]')
|
108 |
+
aria_hidden_value = await examples.get_attribute("aria-hidden")
|
109 |
+
if aria_hidden_value == "true":
|
110 |
+
examples = None
|
111 |
+
print("no examples")
|
112 |
+
else:
|
113 |
+
examples1 = examples.locator('//div[@class="image"]')
|
114 |
+
await examples1.wait_for()
|
115 |
+
style_attribute = await examples1.get_attribute("style")
|
116 |
+
url_match = re.search(r'url\("(.+?)"\)', style_attribute)
|
117 |
+
if url_match:
|
118 |
+
url = url_match.group(1)
|
119 |
+
print(url)
|
120 |
+
examples = url
|
121 |
+
task0 = frame_challenge.locator("//div[@class='task-image']")
|
122 |
+
await frame_challenge.locator("//div[@tabindex='0']").nth(0).wait_for()
|
123 |
+
count = await task0.count()
|
124 |
+
print(span_text)
|
125 |
+
print("done tasks for getting examples")
|
126 |
+
data = []
|
127 |
+
for i in range(count):
|
128 |
+
sample = task0.nth(i)
|
129 |
+
img = sample.locator('//div[@class="image"]')
|
130 |
+
style_attribute = await img.get_attribute("style")
|
131 |
+
url_match = re.search(r'url\("(.+?)"\)', style_attribute)
|
132 |
+
if url_match:
|
133 |
+
url = url_match.group(1)
|
134 |
+
data.append(url)
|
135 |
+
print("done tasks for getting url")
|
136 |
+
await classify_click(page, data, 0, examples, span_text)
|
137 |
else:
|
138 |
+
await asyncio.sleep(random.uniform(0.1, 0.3))
|
139 |
+
await frame_challenge.locator("//div[@class='refresh button']").click()
|
140 |
+
print("refresh")
|
141 |
+
except Exception as e:
|
142 |
+
print(e)
|
143 |
+
await page.close()
|
144 |
+
tasks.cancel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
|
147 |
async def on_response(response, page):
|
|
|
205 |
url = url_match.group(1)
|
206 |
data.append(url)
|
207 |
print("done tasks for getting url")
|
208 |
+
await classify_click(page, data, 1, examples, quetsion0)
|
209 |
except Exception as e:
|
210 |
print(e)
|
211 |
+
await classify_click(page, data, round0, examples, quetsion0)
|
212 |
|
213 |
|
214 |
async def area_click(page, data, round0, examples):
|
|
|
289 |
print(e)
|
290 |
return token
|
291 |
|
292 |
+
# asyncio.run(main("free.vps.vc", "3bae0a5b-f2b8-43ef-98b7-76865a8a3997"))
|
|