コード例 #1
0
class Run(object):
    proxies_loading = True

    def __init__(self, loop):
        self.proxies = ProxyDB(last_banned_timeout=45 * 60)
        self.loop = loop
        if proxy_source:
            asyncio.ensure_future(self.get_proxies(), loop=loop)

    async def get_proxies(self):
        while True:
            self.proxies_loading = True
            print("Proxies loading...")
            protos = ["http://", "https://"]
            if any(p in proxy_source for p in protos):
                f = util.get_page
            else:
                f = util.load_file

            result = await f(proxy_source)
            self.proxies.add(result.split('\n'))
            self.proxies_loading = False
            print("Proxies loaded.")
            await asyncio.sleep(10 * 60)

    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 = self.proxies.get() if proxy_source else None
        proxy_auth = None
        if proxy_username and proxy_password:
            proxy_auth = {"username": proxy_username,
                          "password": proxy_password}
        client = Solver(
            pageurl,
            sitekey,
            options=options,
            loop=self.loop,
            proxy=proxy,
            proxy_auth=proxy_auth
        )
        result = None
        try:
            async with timeout(180):
                result = await client.start()
        finally:
            if sort_position:
                used_positions.remove(this_position)

            if result:
                self.proxies.set_active(proxy, False)
                if result['status'] == "detected":
                    self.proxies.set_banned(proxy)
                else:
                    if result['status'] == "success":
                        return result['code']

    async def main(self):
        if proxy_source:
            while not self.proxies_loading:
                await asyncio.sleep(1)

        tasks = [asyncio.ensure_future(self.work()) for i in range(threads)]
        completed, pending = await asyncio.wait(
            tasks, return_when=asyncio.FIRST_COMPLETED
        )
        count = 0
        while True:
            for task in completed:
                result = task.result()
                if result:
                    count += 1
                    print(f"{count}: {result}")
            pending.add(asyncio.ensure_future(self.work()))
            completed, pending = await asyncio.wait(
                pending, return_when=asyncio.FIRST_COMPLETED
            )
コード例 #2
0
 def __init__(self, loop):
     self.proxies = ProxyDB(last_banned_timeout=45 * 60)
     self.loop = loop
     if proxy_source:
         asyncio.ensure_future(self.get_proxies(), loop=loop)
コード例 #3
0
ファイル: app.py プロジェクト: weaming/GoodByeCatpcha
from functools import partial
from pathlib import Path
from threading import RLock

from aiohttp import web
from async_timeout import timeout

from goodbyecaptcha import util
from goodbyecaptcha.proxy import ProxyDB
from goodbyecaptcha.solver import Solver

SECRET_KEY = "CHANGEME"
BANNED_TIMEOUT = 45 * 60  # 45 minutes
SOLVE_DURATION = 3 * 60  # 3 minutes

proxies = ProxyDB(last_banned_timeout=BANNED_TIMEOUT)
proxy_source = None  # Can be URL or file location
proxy_username, proxy_password = (None, None)

if sys.platform == "win32":
    parent_loop = asyncio.ProactorEventLoop()
    asyncio.set_event_loop(parent_loop)
else:
    parent_loop = asyncio.get_event_loop()
    asyncio.get_child_watcher().attach_loop(parent_loop)

app = web.Application()

# Clear Chrome temporary profiles
dir = f"{Path.home()}/.pyppeteer/.dev_profile"
shutil.rmtree(dir, ignore_errors=True)