async def work(pageurl, sitekey, loop): asyncio.set_event_loop(loop) while 1: fut = asyncio.run_coroutine_threadsafe(proxies.get(), main_loop) proxy = fut.result() options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]} client = Solver( pageurl, sitekey, options=options, proxy=proxy, loop=loop, ) try: task = loop.create_task(client.start()) await task with suppress(BaseException): task.exception() except CancelledError: break else: result = task.result() if result: if result['status'] == "detected": asyncio.run_coroutine_threadsafe(proxies.set_banned(proxy), main_loop) else: if result['status'] == "success": return result['code']
async def work(): # Chromium options and arguments args = ["--timeout 5"] if sort_position: this_position = next(x for x in positions if x not in used_positions) used_positions.append(this_position) args.extend([ "--window-position=%s,%s" % this_position, "--window-size=400,400", ]) options = {"ignoreHTTPSErrors": True, "args": args} proxy = random.choice(proxies) client = Solver(settings["pageurl"], settings["sitekey"], options=options, proxy=proxy) answer = await client.start() if sort_position: used_positions.remove(this_position) return answer
async def work(self): args = ["--timeout 5"] if sort_position: this_position = next(x for x in positions if x not in used_positions) used_positions.append(this_position) args.extend([ "--window-position=%s,%s" % this_position, "--window-size=400,400", ]) options = {"ignoreHTTPSErrors": True, "args": args} proxy = await self.proxies.get() if proxy_source else None client = Solver(pageurl, sitekey, options=options, proxy=proxy) try: async with timeout(180): result = await client.start() finally: if sort_position: used_positions.remove(this_position) if result: await self.proxies.set_active(proxy, False) if result['status'] == "detected": await self.proxies.set_banned(proxy) else: if result['status'] == "success": return result['code']
async def work(pageurl, sitekey, loop): proxy = proxies.get() options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]} client = Solver(pageurl, sitekey, loop=loop, options=options, proxy=proxy) result = await client.start() if result: if result['status'] == "detected": loop.call_soon_threadsafe(proxies.set_banned, proxy) else: if result['status'] == "success": return result['code']
async def work(pageurl, sitekey, task_id): # Chromium options and arguments options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]} async with sem: while True: if proxy_source: proxy = random.choice(proxies) else: proxy = None client = Solver(pageurl, sitekey, options=options, proxy=proxy) task = asyncio.ensure_future(client.start()) await task result = task.result() if result: break tasks.update({task_id: {"status": "finished", "solution": result}})
async def work(pageurl, sitekey, proxy): try: options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]} client = Solver(pageurl, sitekey, options=options, proxy=proxy) result = await client.start() if result: return result except asyncio.CancelledError: if client.launcher: if not client.launcher.chromeClosed: await client.launcher.waitForChromeToClose() raise
async def work(pageurl, sitekey, loop): proxy = await asyncio.wrap_future( asyncio.run_coroutine_threadsafe(proxies.get(), parent_loop)) options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]} client = Solver(pageurl, sitekey, loop=loop, options=options, proxy=proxy) result = await client.start() if result: if result['status'] == "detected": await asyncio.wrap_future( asyncio.run_coroutine_threadsafe(proxies.set_banned(proxy), parent_loop)) else: if result['status'] == "success": return result['code']
async def work(pageurl, sitekey): while not proxies: await asyncio.sleep(1) # Chromium options and arguments options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]} async with sem: proxy = next(proxies) client = Solver(pageurl, sitekey, options=options, proxy=proxy) answer = await client.start() if answer: return answer
async def work(pageurl, sitekey): # Chromium options and arguments options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]} async with sem: if proxy_source: proxy = next(proxies) else: proxy = None client = Solver(pageurl, sitekey, options=options, proxy=proxy) answer = await client.start() if answer: return answer
async def work(pageurl, sitekey): async with timeout(3 * 60) as timer: while not timer.expired: proxy = await proxies.get() if proxy: # Chromium options and arguments options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]} client = Solver(pageurl, sitekey, options=options, proxy=proxy) try: result = await client.start() if result: if result['status'] == "detected": proxies.set_banned(proxy) else: if result['status'] == "success": return result['code'] except CancelledError: return
async def work(pageurl, sitekey, loop): proxy = asyncio.run_coroutine_threadsafe(proxies.get(), main_loop).result() options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]} client = Solver( pageurl, sitekey, options=options, proxy=proxy, loop=loop, ) try: result = await client.start() except: raise else: if result: if result['status'] == "detected": asyncio.run_coroutine_threadsafe(proxies.set_banned(proxy), main_loop) else: if result['status'] == "success": return result['code']
import asyncio import sys from nonocaptcha.solver import Solver if len(sys.argv) == 4: pageurl, sitekey, proxy = sys.argv[1:] else: print('Invalid number of arguments (pageurl, sitekey, proxy)') sys.exit(0) loop = asyncio.get_event_loop() options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]} if proxy.lower() == "none": proxy = None client = Solver(pageurl, sitekey, options=options, proxy=proxy) try: result = loop.run_until_complete(client.start()) except asyncio.CancelledError: raise else: if result: print(result)
# for i in range(21, 35): # print("http://xunleib.zuida360.com/1805/逆缘国语-"+str(i).zfill(2)+".mp4") import asyncio from nonocaptcha.solver import Solver pageurl = "https://www.google.com/recaptcha/api2/demo" sitekey = "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-" proxy = "127.0.0.1:1000" auth_details = {"username": "******", "password": "******"} args = ["--timeout 5"] options = {"ignoreHTTPSErrors": True, "args": args} client = Solver( pageurl, sitekey, options=options, proxy=proxy, proxy_auth=auth_details, ) solution = asyncio.get_event_loop().run_until_complete(client.start()) if solution: print(solution)
import asyncio from nonocaptcha.solver import Solver pageurl = "https://www.google.com/recaptcha/api2/demo" sitekey = "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-" options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5", "--no-sandbox"]} client = Solver(pageurl, sitekey, options=options) solution = asyncio.get_event_loop().run_until_complete(client.start()) if solution: print(solution)
def signal_handler(signal, frame): asyncio.ensure_future(kill_chrome()) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGHUP, signal_handler) try: proxy_auth = {"username": proxy_username, "password": proxy_password} options = {"ignoreHTTPSErrors": True, "args": ["--timeout 5"]} client = Solver( pageurl, sitekey, options=options, proxy=proxy, proxy_auth=proxy_auth ) result = asyncio.get_event_loop().run_until_complete( client.start() ) except asyncio.CancelledError: asyncio.get_event_loop().run_until_complete( kill_chrome() ) else: if result: print(result)