當前位置: 首頁>>代碼示例>>Python>>正文


Python pyppeteer.launch方法代碼示例

本文整理匯總了Python中pyppeteer.launch方法的典型用法代碼示例。如果您正苦於以下問題:Python pyppeteer.launch方法的具體用法?Python pyppeteer.launch怎麽用?Python pyppeteer.launch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyppeteer的用法示例。


在下文中一共展示了pyppeteer.launch方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _html_to_pdf

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def _html_to_pdf(html_file, pdf_file):
    try:
        from pyppeteer import launch
    except ImportError:
        _error(
            "Generating PDF from book HTML requires the pyppeteer package. "
            "Install it first.",
            ImportError,
        )
    browser = await launch(args=["--no-sandbox"])
    page = await browser.newPage()

    # Absolute path is needed
    html_file = Path(html_file).resolve()

    # Waiting for networkidle0 seems to let mathjax render
    await page.goto(f"file:///{html_file}", {"waitUntil": ["networkidle0"]})
    # Give it *some* margins to make it look a little prettier
    # I just made these up
    page_margins = {"left": "0in", "right": "0in", "top": ".5in", "bottom": ".5in"}
    await page.pdf({"path": pdf_file, "margin": page_margins})
    await browser.close() 
開發者ID:executablebooks,項目名稱:jupyter-book,代碼行數:24,代碼來源:pdf.py

示例2: get_browser_connection_url

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
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 
開發者ID:limitedeternity,項目名稱:foxford_courses,代碼行數:20,代碼來源:browser.py

示例3: main

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def main():
    browser = await launch(headless=False)
    page = await browser.newPage()

    # await stealth(page)

    await page.goto("https://bot.sannysoft.com/")
    await page.screenshot({"path": "headful_without_stealth.png", "fullPage": True})
    await browser.close() 
開發者ID:MeiK2333,項目名稱:pyppeteer_stealth,代碼行數:11,代碼來源:headful_without_stealth.py

示例4: main

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def main():
    browser = await launch(headless=True)
    page = await browser.newPage()

    await stealth(page)

    await page.goto("https://bot.sannysoft.com/")
    await page.screenshot({"path": "headless_with_stealth.png", "fullPage": True})
    await browser.close() 
開發者ID:MeiK2333,項目名稱:pyppeteer_stealth,代碼行數:11,代碼來源:headless_with_stealth.py

示例5: main

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def main():
    browser = await launch(headless=False)
    page = await browser.newPage()

    await stealth(page)

    await page.goto("https://bot.sannysoft.com/")
    await page.screenshot({"path": "headful_with_stealth.png", "fullPage": True})
    await browser.close() 
開發者ID:MeiK2333,項目名稱:pyppeteer_stealth,代碼行數:11,代碼來源:headful_with_stealth.py

示例6: main

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def main():
    browser = await launch(headless=True)
    page = await browser.newPage()

    # await stealth(page)

    await page.goto("https://bot.sannysoft.com/")
    await page.screenshot({"path": "headless_without_stealth.png", "fullPage": True})
    await browser.close() 
開發者ID:MeiK2333,項目名稱:pyppeteer_stealth,代碼行數:11,代碼來源:headless_without_stealth.py

示例7: __config_browser

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def __config_browser(username: str = None, save_session: bool = False):
    __logger.debug('Configuring Browser.')
    if username is not None and username.strip() != '' and save_session:
        return await launch(headless=False, autoClose=False, userDataDir=user_data_folder_path / username)
    else:
        return await launch(headless=False, autoClose=False) 
開發者ID:rpotter12,項目名稱:whatsapp-play,代碼行數:8,代碼來源:browser_config.py

示例8: takeScreenshot

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def takeScreenshot(qry):
    browser = await launch()
    page = await browser.newPage()
    await page.goto('https://www.google.com/search?q={}&source=lnms&tbm=isch'.format(qry))
    image_path = str(chatbot_image_folder_path / '{}.png'.format(qry))
    await page.screenshot({'path': image_path})
    await browser.close() 
開發者ID:rpotter12,項目名稱:whatsapp-play,代碼行數:9,代碼來源:chatbot.py

示例9: create_and_upload_pdf

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def create_and_upload_pdf(file_name: str, pages: List[str], object_name: str, s3_helper: S3Helper):
    """Create a PDF file with the given pages using pyppeteer.
    """
    # --no-sandbox is required to make Chrome/Chromium run under root.
    browser = await launch(
        handleSIGINT=False,
        handleSIGTERM=False,
        handleSIGHUP=False,
        args=["--no-sandbox"],
    )

    async def render_page(url):
        page = await browser.newPage()
        logger.info("Getting: {}".format(url))
        await page.goto(url, {"waitUntil": "networkidle0"})
        logger.info("Got: {}".format(url))
        return BytesIO(await page.pdf({"format": "A4", "printBackground": True}))

    chunks = await asyncio.gather(*[
        render_page(url) for url in pages
    ])

    await browser.close()

    # merge all pages
    writer = PdfFileWriter()
    # for page in pages:
    for chunk in chunks:
        reader = PdfFileReader(chunk)
        for index in range(reader.numPages):
            writer.addPage(reader.getPage(index))

    with open(file_name, "wb") as output:
        writer.write(output)

    s3_helper.upload_file(file_name, object_name) 
開發者ID:GFDRR,項目名稱:thinkhazard,代碼行數:38,代碼來源:pdf.py

示例10: _internal_start_driver

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def _internal_start_driver(self):
        self.driver = await launch(
            **self.options)
        pages = await self.driver.pages()
        self.page = pages[0]
        await self.page.setUserAgent(
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 '
            '(KHTML, like Gecko) Chrome/65.0.3312.0 Safari/537.36'
        )
        await self.page.setViewport({'width': 800, 'height': 600})
        await self.page.exposeFunction('whalesongPushResult', self.process_result_sync) 
開發者ID:alfred82santa,項目名稱:whalesong,代碼行數:13,代碼來源:driver_chromium.py

示例11: start_scan

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def start_scan(queue, n_urls: int):
    logging.info("Starting headless browser")
    browser = await pyppeteer.launch(headless=True, ignoreHTTPSErrors=True, args=['--no-sandbox']) # --no-sandbox is required to make Chrome/Chromium run under root.
    context = await browser.createIncognitoBrowserContext()

    try:
        worker_threads = [asyncio.create_task(worker(context, queue)) for _ in range(n_urls)]
        logging.info(f"Using {len(worker_threads)} worker thread(s)")
        await asyncio.gather(*worker_threads, return_exceptions=True)
    finally:
        await context.close()
        logging.info("Killing headless browser")
        await browser.close() 
開發者ID:byt3bl33d3r,項目名稱:WitnessMe,代碼行數:15,代碼來源:witnessme.py

示例12: browser

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
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 
開發者ID:psf,項目名稱:requests-html,代碼行數:7,代碼來源:requests_html.py

示例13: find_redirect

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
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)

            # await self.page.emulate({'viewport': {
            #    'width': random.randint(320, 1920),
            #    'height': random.randint(320, 1920),
            #    'deviceScaleFactor': random.randint(1, 3),
            #    'isMobile': random.random() > 0.5,
            #    'hasTouch': random.random() > 0.5
            # }})

            # await self.page.setUserAgent(self.userAgent)

            await self.page.goto(self.url, {
                'waitUntil': "load"
            })

            self.redirect_url = self.page.url

            await self.browser.close()

        except:
            await self.browser.close() 
開發者ID:davidteather,項目名稱:TikTok-Api,代碼行數:41,代碼來源:browser.py

示例14: main

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def main(self):
        # Proxy can be used to debug: ,'--proxy-server=http://127.0.0.1:8080'])
        browser = await launch(headless=False, args=['--no-sandbox'])
        page = await browser.newPage()
        for user, passwd in zip(self.users, self.passwords):
            await self.flow(page, user, passwd)
        await browser.close() 
開發者ID:FSecureLABS,項目名稱:captcha22,代碼行數:9,代碼來源:pyppeteer.py

示例15: start

# 需要導入模塊: import pyppeteer [as 別名]
# 或者: from pyppeteer import launch [as 別名]
def start(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)

            # await self.page.emulate({
            #    'viewport': {'width': random.randint(320, 1920), 'height': random.randint(320, 1920), },
            #    'deviceScaleFactor': random.randint(1, 3),
            #    'isMobile': random.random() > 0.5,
            #    'hasTouch': random.random() > 0.5
            # })
            await self.page.goto("https://www.tiktok.com/@floofybastard?lang=" + self.language, {
                'waitUntil': "load"
            })
            self.userAgent = await self.page.evaluate("""() => {return navigator.userAgent; }""")

            for c in await self.page.cookies():
                if c['name'] == "s_v_web_id":
                    self.verifyFp = c['value']

            if self.verifyFp == None:
                self.verifyFp = ""

            self.signature = await self.page.evaluate('''() => {
            var url = "''' + self.url + "&verifyFp=" + self.verifyFp + '''"
            var token = window.byted_acrawler.sign({url: url});
            return token;
            }''')

            if self.api_url != None:
                await self.page.goto(self.url +
                                    "&verifyFp=" + self.verifyFp +
                                    "&_signature=" + self.signature, {
                                        'waitUntil': "load"
                                    })

                self.data = await self.page.content()
                print(self.data)
                #self.data = await json.loads(self.data)

            await self.browser.close()
        except:
            await self.browser.close() 
開發者ID:davidteather,項目名稱:TikTok-Api,代碼行數:59,代碼來源:browser.py


注:本文中的pyppeteer.launch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。