当前位置: 首页>>代码示例>>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;未经允许,请勿转载。