本文整理汇总了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()
示例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
示例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()
示例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()
示例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()
示例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()
示例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)
示例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()
示例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)
示例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)
示例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()
示例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
示例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()
示例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()
示例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()