コード例 #1
0
    def __init__(self, options: Dict[str, Any] = None, **kwargs: Any) -> None:
        """Make new launcher."""
        self.options = merge_dict(options, kwargs)
        self.port = get_free_port()
        self.url = f'http://127.0.0.1:{self.port}'

        self.chrome_args = DEFAULT_ARGS
        self.chrome_args.append(f'--remote-debugging-port={self.port}', )
        self.chromeClosed = True
        if self.options.get('appMode', False):
            self.options['headless'] = False
        else:
            self.chrome_args.extend(AUTOMATION_ARGS)

        self._tmp_user_data_dir: Optional[str] = None
        self._parse_args()

        if self.options.get('devtools'):
            self.chrome_args.append('--auto-open-devtools-for-tabs')
            self.options['headless'] = False

        if 'headless' not in self.options or self.options.get('headless'):
            self.chrome_args = self.chrome_args + [
                '--headless',
                '--disable-gpu',
                '--hide-scrollbars',
                '--mute-audio',
            ]
        if 'executablePath' in self.options:
            self.exec = self.options['executablePath']
        else:
            if not check_chromium():
                download_chromium()
            self.exec = str(chromium_excutable())
        self.cmd = [self.exec] + self.chrome_args
コード例 #2
0
ファイル: launcher.py プロジェクト: parejadan/nonoCAPTCHA
    def __init__(self, options,  # noqa: C901
                 **kwargs) -> None:
        """Make new launcher."""
        self.options = merge_dict(options, kwargs)
        self.port = get_free_port()
        self.url = f'http://127.0.0.1:{self.port}'
        self.chrome_args = [f'--remote-debugging-port={self.port}']
        self._loop = self.options.get('loop', asyncio.get_event_loop())

        logLevel = self.options.get('logLevel')
        if logLevel:
            logging.getLogger('pyppeteer').setLevel(logLevel)
        self.chromeClosed = True
        if self.options.get('appMode', False):
            self.options['headless'] = False
        self._tmp_user_data_dir = self.options.get('userDataDir', None)
        self._parse_args()
        if self.options.get('devtools'):
            self.chrome_args.append('--auto-open-devtools-for-tabs')
            self.options['headless'] = False
        if 'headless' not in self.options or self.options.get('headless'):
            self.chrome_args.extend([
                '--headless',
                '--disable-gpu',
                '--hide-scrollbars',
                '--mute-audio',
            ])
        if 'executablePath' in self.options:
            self.exec = self.options['executablePath']
        else:
            if not check_chromium():
                download_chromium()
            self.exec = str(chromium_executable())
        self.cmd = [self.exec] + self.chrome_args
コード例 #3
0
 def setUpClass(cls):
     cls.port = get_free_port()
     time.sleep(0.1)
     cls.app = get_application()
     cls.server = cls.app.listen(cls.port)
     cls.browser = launch()
     cls.page = sync(cls.browser.newPage())
コード例 #4
0
 def setUpClass(cls):
     cls.port = get_free_port()
     cls.url = 'http://localhost:{}/'.format(cls.port)
     cls.app = get_application()
     time.sleep(0.1)
     cls.server = cls.app.listen(cls.port)
     cls.browser = launch(headless=True)
コード例 #5
0
 def setUpClass(cls):
     cls.port = get_free_port()
     cls.url = 'http://localhost:{}/'.format(cls.port)
     cls.app = get_application()
     time.sleep(0.1)
     cls.server = cls.app.listen(cls.port)
     cls.browser = launch(args=['--no-sandbox'])
コード例 #6
0
 def __init__(self,
              options: Dict[(str, Any)] = None,
              **kwargs: Any) -> None:
     'Make new launcher.'
     self.options = merge_dict(options, kwargs)
     self.port = get_free_port()
     self.url = ''.join(['http://127.0.0.1:', '{}'.format(self.port)])
     self.chrome_args = []
     if (not self.options.get('ignoreDefaultArgs', False)):
         self.chrome_args.extend(DEFAULT_ARGS)
         self.chrome_args.append(''.join(
             ['--remote-debugging-port=', '{}'.format(self.port)]))
     self.chromeClosed = True
     if self.options.get('appMode', False):
         self.options['headless'] = False
     elif (not self.options.get('ignoreDefaultArgs', False)):
         self.chrome_args.extend(AUTOMATION_ARGS)
     self._tmp_user_data_dir = None
     self._parse_args()
     if self.options.get('devtools'):
         self.chrome_args.append('--auto-open-devtools-for-tabs')
         self.options['headless'] = False
     if (('headless' not in self.options) or self.options.get('headless')):
         self.chrome_args.extend([
             '--headless', '--disable-gpu', '--hide-scrollbars',
             '--mute-audio'
         ])
     if ('executablePath' in self.options):
         self.exec = self.options['executablePath']
     else:
         if (not check_chromium()):
             download_chromium()
         self.exec = str(chromium_excutable())
     self.cmd = ([self.exec] + self.chrome_args)
コード例 #7
0
    def __init__(
            self,
            options: Dict[str, Any] = None,  # noqa: C901
            **kwargs: Any) -> None:
        """Make new launcher."""
        self.options = merge_dict(options, kwargs)
        self.port = get_free_port()
        self.url = f'http://127.0.0.1:{self.port}'
        self.chrome_args: List[str] = []
        self._loop = self.options.get('loop', asyncio.get_event_loop())

        logLevel = self.options.get('logLevel')
        if logLevel:
            logging.getLogger('pyppeteer').setLevel(logLevel)

        if not self.options.get('ignoreDefaultArgs', False):
            self.chrome_args.extend(DEFAULT_ARGS)
            self.chrome_args.append(f'--remote-debugging-port={self.port}', )

        self.chromeClosed = True
        if self.options.get('appMode', False):
            self.options['headless'] = False
        elif not self.options.get('ignoreDefaultArgs', False):
            self.chrome_args.extend(AUTOMATION_ARGS)

        self._tmp_user_data_dir: Optional[str] = None
        self._parse_args()

        if self.options.get('devtools'):
            self.chrome_args.append('--auto-open-devtools-for-tabs')
            self.options['headless'] = False

        if 'headless' not in self.options or self.options.get('headless'):
            self.chrome_args.extend([
                '--headless',
                '--disable-gpu',
                '--hide-scrollbars',
                '--mute-audio',
            ])

        def _is_default_url() -> bool:
            for arg in self.options['args']:
                if not arg.startswith('-'):
                    return False
            return True

        if (not self.options.get('ignoreDefaultArgs')
                and isinstance(self.options.get('args'), list)
                and _is_default_url()):
            self.chrome_args.append('about:blank')

        if 'executablePath' in self.options:
            self.exec = self.options['executablePath']
        else:
            if not check_chromium():
                download_chromium()
            self.exec = str(chromium_executable())

        self.cmd = [self.exec] + self.chrome_args
コード例 #8
0
ファイル: launcher.py プロジェクト: fvinas/pyppeteer
    def __init__(self, options: Dict[str, Any] = None,  # noqa: C901
                 **kwargs: Any) -> None:
        """Make new launcher."""
        self.options = merge_dict(options, kwargs)
        self.port = get_free_port()
        self.url = f'http://127.0.0.1:{self.port}'
        self.chrome_args: List[str] = []
        self._loop = self.options.get('loop', asyncio.get_event_loop())

        logLevel = self.options.get('logLevel')
        if logLevel:
            logging.getLogger('pyppeteer').setLevel(logLevel)

        if not self.options.get('ignoreDefaultArgs', False):
            self.chrome_args.extend(DEFAULT_ARGS)
            self.chrome_args.append(
                f'--remote-debugging-port={self.port}',
            )

        self.chromeClosed = True
        if self.options.get('appMode', False):
            self.options['headless'] = False
        elif not self.options.get('ignoreDefaultArgs', False):
            self.chrome_args.extend(AUTOMATION_ARGS)

        self._tmp_user_data_dir: Optional[str] = None
        self._parse_args()

        if self.options.get('devtools'):
            self.chrome_args.append('--auto-open-devtools-for-tabs')
            self.options['headless'] = False

        if 'headless' not in self.options or self.options.get('headless'):
            self.chrome_args.extend([
                '--headless',
                '--disable-gpu',
                '--hide-scrollbars',
                '--mute-audio',
            ])

        def _is_default_url() -> bool:
            for arg in self.options['args']:
                if not arg.startswith('-'):
                    return False
            return True

        if (not self.options.get('ignoreDefaultArgs') and
                isinstance(self.options.get('args'), list) and
                _is_default_url()):
            self.chrome_args.append('about:blank')

        if 'executablePath' in self.options:
            self.exec = self.options['executablePath']
        else:
            if not check_chromium():
                download_chromium()
            self.exec = str(chromium_executable())

        self.cmd = [self.exec] + self.chrome_args
コード例 #9
0
ファイル: launcher.py プロジェクト: enquora/pyppeteer
    def __init__(self, options: Dict[str, Any] = None,  # noqa: C901
                 **kwargs: Any) -> None:
        """Make new launcher."""
        options = merge_dict(options, kwargs)

        self.port = get_free_port()
        self.url = f'http://127.0.0.1:{self.port}'
        self._loop = options.get('loop', asyncio.get_event_loop())
        self.chromeClosed = True

        ignoreDefaultArgs = options.get('ignoreDefaultArgs', False)
        args: List[str] = options.get('args', list())
        self.dumpio = options.get('dumpio', False)
        executablePath = options.get('executablePath')
        self.env = options.get('env')
        self.handleSIGINT = options.get('handleSIGINT', True)
        self.handleSIGTERM = options.get('handleSIGTERM', True)
        self.handleSIGHUP = options.get('handleSIGHUP', True)
        self.ignoreHTTPSErrors = options.get('ignoreHTTPSErrors', False)
        self.defaultViewport = options.get('defaultViewport', {'width': 800, 'height': 600})  # noqa: E501
        self.slowMo = options.get('slowMo', 0)
        self.timeout = options.get('timeout', 30000)
        self.autoClose = options.get('autoClose', True)

        logLevel = options.get('logLevel')
        if logLevel:
            logging.getLogger('pyppeteer').setLevel(logLevel)

        self.chromeArguments: List[str] = list()
        if not ignoreDefaultArgs:
            self.chromeArguments.extend(defaultArgs(options))
        elif isinstance(ignoreDefaultArgs, list):
            self.chromeArguments.extend(filter(
                lambda arg: arg not in ignoreDefaultArgs,
                defaultArgs(options),
            ))
        else:
            self.chromeArguments.extend(args)

        self.temporaryUserDataDir: Optional[str] = None

        if not any(arg for arg in self.chromeArguments
                   if arg.startswith('--remote-debugging-')):
            self.chromeArguments.append(f'--remote-debugging-port={self.port}')

        if not any(arg for arg in self.chromeArguments
                   if arg.startswith('--user-data-dir')):
            if not CHROME_PROFILE_PATH.exists():
                CHROME_PROFILE_PATH.mkdir(parents=True)
            self.temporaryUserDataDir = tempfile.mkdtemp(dir=str(CHROME_PROFILE_PATH))  # noqa: E501
            self.chromeArguments.append(f'--user-data-dir={self.temporaryUserDataDir}')  # noqa: E501

        self.chromeExecutable = executablePath
        if not self.chromeExecutable:
            if not check_chromium():
                download_chromium()
            self.chromeExecutable = str(chromium_executable())

        self.cmd = [self.chromeExecutable] + self.chromeArguments
コード例 #10
0
ファイル: test_launcher.py プロジェクト: fvinas/pyppeteer
 async def test_ignore_https_errors(self):
     browser = await launch(DEFAULT_OPTIONS, ignoreHTTPSErrors=True)
     page = await browser.newPage()
     port = get_free_port()
     time.sleep(0.1)
     app = get_application()
     server = app.listen(port)
     response = await page.goto('https://localhost:{}'.format(port))
     self.assertTrue(response.ok)
     await browser.close()
     server.stop()
コード例 #11
0
 async def test_ignore_https_errors(self):
     browser = await launch(DEFAULT_OPTIONS, ignoreHTTPSErrors=True)
     page = await browser.newPage()
     port = get_free_port()
     time.sleep(0.1)
     app = get_application()
     server = app.listen(port)
     response = await page.goto('https://localhost:{}'.format(port))
     self.assertTrue(response.ok)
     await browser.close()
     server.stop()
コード例 #12
0
ファイル: launcher.py プロジェクト: Tilyp/pyppeteer
    def __init__(self, options: Dict[str, Any] = None,  # noqa: C901
                 **kwargs: Any) -> None:
        """Make new launcher."""
        self.options = merge_dict(options, kwargs)
        self.port = get_free_port()
        self.url = f'http://127.0.0.1:{self.port}'
        self.chrome_args: List[str] = []

        if not self.options.get('ignoreDefaultArgs', False):
            self.chrome_args.extend(DEFAULT_ARGS)
            self.chrome_args.append(
                f'--remote-debugging-port={self.port}',
            )

        self.chromeClosed = True
        if self.options.get('appMode', False):
            self.options['headless'] = False
        elif not self.options.get('ignoreDefaultArgs', False):
            self.chrome_args.extend(AUTOMATION_ARGS)

        self._tmp_user_data_dir: Optional[str] = None
        self._parse_args()

        if self.options.get('devtools'):
            self.chrome_args.append('--auto-open-devtools-for-tabs')
            self.options['headless'] = False

        if 'headless' not in self.options or self.options.get('headless'):
            self.chrome_args.extend([
                '--headless',
                '--disable-gpu',
                '--hide-scrollbars',
                '--mute-audio',
            ])

        if 'executablePath' in self.options:
            self.exec = self.options['executablePath']
        else:
            if not check_chromium():
                download_chromium()
            self.exec = str(chromium_excutable())

        self.cmd = [self.exec] + self.chrome_args
コード例 #13
0
ファイル: base.py プロジェクト: zhangzhaolei/pyppeteer
 def setUpClass(cls):
     cls.port = get_free_port()
     cls.app = get_application()
     cls.server = cls.app.listen(cls.port)
     cls.browser = sync(launch(DEFAULT_OPTIONS))
     cls.url = 'http://localhost:{}/'.format(cls.port)
コード例 #14
0
ファイル: test_launcher.py プロジェクト: fvinas/pyppeteer
 def setUpClass(cls):
     cls.port = get_free_port()
     time.sleep(0.1)
     cls.app = get_application()
     cls.server = cls.app.listen(cls.port)
     cls.url = 'http://localhost:{}/'.format(cls.port)
コード例 #15
0
ファイル: base.py プロジェクト: fvinas/pyppeteer
 def setUpClass(cls):
     cls.port = get_free_port()
     cls.app = get_application()
     cls.server = cls.app.listen(cls.port)
     cls.browser = sync(launch(DEFAULT_OPTIONS))
     cls.url = 'http://localhost:{}/'.format(cls.port)