Pandaaaa906

weird_pyppeteer

May 16th, 2019
198
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import asyncio
  2.  
  3. from pyppeteer import launch
  4.  
  5. args = ['--no-sandbox',
  6.         '--disable-setuid-sandbox',
  7.         '--disable-infobars',
  8.         '--window-position=0,0',
  9.         '--ignore-certifcate-errors',
  10.         '--ignore-certifcate-errors-spki-list',
  11.         '--disable-gpu',
  12.         '--user-agent=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'
  13.         ]
  14.  
  15.  
  16. async def new_page(headless=True, preloads=("preload.js",)):
  17.     browser = await launch(ignoreHTTPSErrors=True,
  18.                            headless=headless,
  19.                            userDataDir='./tmp',
  20.                            # executablePath="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
  21.                            args=args)
  22.     page = await browser.newPage()
  23.     await page.setViewport({'width': 1400, 'height': 900})
  24.     for fp in preloads:
  25.         with open(fp) as f:
  26.             preload_js = f.read()
  27.         await page.evaluateOnNewDocument(preload_js)
  28.     return page
  29.  
  30.  
  31. if __name__ == '__main__':
  32.     async def main():
  33.         page = await new_page(headless=False, preloads=())
  34.         page = await new_page(headless=False, preloads=())
  35.  
  36.  
  37.     loop = asyncio.get_event_loop()
  38.     loop.run_until_complete(main())
RAW Paste Data