Home
About
Resume
Projects
Links
Blog
Back to Contents
# Python Capture Webpage using pyppeteer #### Installation ```bash pip install pyppeteer ``` #### Usage Please refer to [Pyppeteer’s documentation](https://pyppeteer.github.io/pyppeteer/) #### Working Example ##### Aim: - To capture the information page of datasets from NCBI database ##### Code: ```python import asyncio, os from pyppeteer import launch #### Define Functions ##### class Webscreenshooter(): def gen_output_path(self, gse_id, output_dir): file_name = f"temp_{gse_id}.png" output_path = os.path.join(output_dir, file_name) return output_path, file_name async def screenshot(self, url, output_path): browser = await launch(args=['--no-sandbox']) page = await browser.newPage() await page.setViewport({'width': 800, 'height': 1600}) await page.goto(url) await page.screenshot({'path': output_path}) await browser.close() def take_screenshot(self, gse_id, output_path): url = 'https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc='+gse_id asyncio.get_event_loop().run_until_complete(self.screenshot(url, output_path)) #print('web screenshot complete') ########################## GSE_ID_LIST = ["GSE64456","GSE72829"] ws = Webscreenshooter() for gse_id in GSE_ID_LIST: output_path, file_name = ws.gen_output_path(gse_id, output_dir) ws.take_screenshot(gse_id, output_path) ``` #### Source **Documentation link**: [Pyppeteer’s documentation](https://pyppeteer.github.io/pyppeteer/)
Previous Post:
Python Covert PNG to PDF
Loading