Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- from pyppeteer import launch
- args = ['--no-sandbox',
- '--disable-setuid-sandbox',
- '--disable-infobars',
- '--window-position=0,0',
- '--ignore-certifcate-errors',
- '--ignore-certifcate-errors-spki-list',
- '--disable-gpu',
- '--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'
- ]
- async def new_page(headless=True, preloads=("preload.js",)):
- browser = await launch(ignoreHTTPSErrors=True,
- headless=headless,
- userDataDir='./tmp',
- # executablePath="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
- args=args)
- page = await browser.newPage()
- await page.setViewport({'width': 1400, 'height': 900})
- for fp in preloads:
- with open(fp) as f:
- preload_js = f.read()
- await page.evaluateOnNewDocument(preload_js)
- return page
- if __name__ == '__main__':
- async def main():
- page = await new_page(headless=False, preloads=())
- page = await new_page(headless=False, preloads=())
- loop = asyncio.get_event_loop()
- loop.run_until_complete(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement