Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- from pyppeteer import launch
- async def save(content, extension):
- file = open(f"result.{extension}", 'w+')
- file.write(content)
- file.close()
- async def main(contentType):
- browser = await launch()
- page = await browser.newPage()
- await page.goto('https://example.com')
- await page.screenshot({'path': 'example.png'})
- if contentType == 'html':
- # 1 get the html contnet
- content = await page.evaluate('document.body.innerHTML', force_expr=True)
- print(content)
- # 2 get the text
- elif contentType == 'txt':
- content = await page.evaluate('document.body.textContent', force_expr=True)
- print(content)
- await save(content, 'html')
- await browser.close()
- contentType = input('What do you want to save: html or txt: ')
- asyncio.get_event_loop().run_until_complete(main(contentType))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement