How to use the pyppeteer.launch function in pyppeteer

To help you get started, we’ve selected a few pyppeteer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github miyakogi / pyppeteer / tests / test_launcher.py View on Github external
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()
github miyakogi / pyppeteer / tests / test_launcher.py View on Github external
async def test_user_data_dir_restore_cookie_in_browser(self):
        browser = await launch(
            DEFAULT_OPTIONS, userDataDir=self.datadir, headless=False)
        page = await browser.newPage()
        await page.goto(self.url + 'empty')
        await page.evaluate('() => document.cookie = "foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT"')  # noqa: E501
        await browser.close()

        browser2 = await launch(DEFAULT_OPTIONS, userDataDir=self.datadir)
        page2 = await browser2.newPage()
        await page2.goto(self.url + 'empty')
        result = await page2.evaluate('() => document.cookie')
        await browser2.close()
        self.assertEqual(result, 'foo=true')
github miyakogi / pyppeteer / tests / test_launcher.py View on Github external
async def test_launch(self):
        browser = await launch(DEFAULT_OPTIONS)
        await browser.newPage()
        await browser.close()
github davidteather / TikTok-Api / TikTokApi / browser.py View on Github external
async def find_redirect(self):
        try:
            self.browser = await pyppeteer.launch(self.options)
            self.page = await self.browser.newPage()

            await self.page.evaluateOnNewDocument("""() => {
        delete navigator.__proto__.webdriver;
    }""")

            # Check for user:pass proxy
            if self.proxy != None:
                if "@" in self.proxy:
                    await self.page.authenticate({
                        'username': self.proxy.split("://")[1].split(":")[0],
                        'password': self.proxy.split("://")[1].split(":")[1].split("@")[0]
                    })

            await stealth(self.page)
github python-ruia / ruia-pyppeteer / ruia_pyppeteer / request.py View on Github external
async def fetch(self) -> PyppeteerResponse:
        """Fetch all the information by using aiohttp"""
        if self.request_config.get("DELAY", 0) > 0:
            await asyncio.sleep(self.request_config["DELAY"])

        timeout = self.request_config.get("TIMEOUT", 10)
        try:
            if self.load_js:
                if not hasattr(self, "browser"):
                    self.pyppeteer_args.extend(["--no-sandbox"])
                    self.browser = await pyppeteer.launch(
                        headless=True,
                        args=self.pyppeteer_args,
                        options=self.pyppeteer_launch_options,
                    )
                page = await self.browser.newPage()
                self.pyppeteer_page_options.update({"timeout": int(timeout * 1000)})

                resp = await page.goto(self.url, options=self.pyppeteer_page_options)
                await page.setViewport(self.pyppeteer_viewport)

                resp_data = await page.content()
                response = PyppeteerResponse(
                    url=self.url,
                    method=self.method,
                    encoding=self.encoding,
                    html=resp_data,
github psf / requests-html / requests_html.py View on Github external
async def browser(self):
        if not hasattr(self, "_browser"):
            self._browser = await pyppeteer.launch(ignoreHTTPSErrors=not(self.verify), headless=True, args=self.__browser_args)

        return self._browser
github limitedeternity / foxford_courses / foxford_downloader / lib / browser.py View on Github external
async def get_browser_connection_url() -> str:
    browser = await launch(
        ignoreHTTPSErrors=True,
        headless=True,
        slowMo=0,
        args=[
            "--no-sandbox",
            "--disable-setuid-sandbox",
            "--disable-gpu",
            "--disable-dev-shm-usage",
            '--proxy-server="direct://"',
            "--proxy-bypass-list=*"
        ]
    )

    connectionUrl = browser.wsEndpoint
    await browser.disconnect()
    return connectionUrl
github jclgoodwin / bustimes.org / vehicles / management / commands / import_cambridge.py View on Github external
async def get_client_data(self):
        browser = await pyppeteer.launch(handleSIGINT=False)
        page = await browser.newPage()
        await page.goto(self.source.url)
        client_data = await page.evaluate('CLIENT_DATA')
        url = await page.evaluate('RTMONITOR_URI')
        origin = await page.evaluate('window.location.origin')
        await browser.close()
        return client_data, url.replace('https://', 'wss://') + 'websocket', origin
github lopuhin / scrapy-pyppeteer / scrapy_pyppeteer / middleware.py View on Github external
async def process_browser_request(self, request: BrowserRequest):
        if self._browser is None:
            self._browser = await pyppeteer.launch(**self._launch_options)
        page = await self._browser.newPage()
        n_tabs = _n_browser_tabs(self._browser)
        logger.debug(f'{n_tabs} tabs open')
        if request.is_blank:
            url = request.url
        else:
            await page.goto(request.url)
            url = page.url
            # TODO set status and headers
        return BrowserResponse(url=url, browser_tab=page)
github higlass / higlass-server / website / views.py View on Github external
async def screenshot(
    base_url: str,
    uuid: str,
    output_file: str
):
    '''Take a screenshot of a rendered viewconf.

    Args:
        base_url: The url to use for rendering the viewconf
        uuid: The uuid of the viewconf to render
        output_file: The location on the local filesystem to cache
            the thumbnail.
    Returns:
        Nothing, just stores the screenshot at the given location.
    '''
    browser = await launch(
        headless=True,
        args=['--no-sandbox'],
        handleSIGINT=False,
        handleSIGTERM=False,
        handleSIGHUP=False
    )
    url = f'{base_url}?config={uuid}'
    page = await browser.newPage()
    await page.goto(url, {
        'waitUntil': 'networkidle0',
    })
    await page.screenshot({'path': output_file})
    await browser.close()