Lindsay's DataStack

Lindsay's DataStack

Share this post

Lindsay's DataStack
Lindsay's DataStack
Scrape a dashboard and send it inline and as a .pdf via email
Copy link
Facebook
Email
Notes
More

Scrape a dashboard and send it inline and as a .pdf via email

Make your VP happy!

Lindsay M. Pettingill's avatar
Lindsay M. Pettingill
Mar 14, 2024
∙ Paid

Share this post

Lindsay's DataStack
Lindsay's DataStack
Scrape a dashboard and send it inline and as a .pdf via email
Copy link
Facebook
Email
Notes
More
Share

Last week I suggested that it would be fun to scape a dashboard and send it as a email to an executive. Today we’ll do it using Python.

The finished product

To start:

  • This example assumes you have a Gmail account.

  • Since you are using an app (Python) to send email, Google requires you to set up an “app password”. This is a security measure required by Google. Instructions here; you’ll use this app password (not your Gmail password) to authenticate and send the screenshot and .pdf from your Google Account.

I am assuming you’ll run this code in a cloud-based notebook. It’s very lightweight and you should be up and running pretty quickly.

First, install required packages:

pip install asyncio
pip install pyppeteer
pip install img2pdf

You’ll use `pyppeteer` to open a webpage and take a screenshot. `asyncio` basically delays that action (to give the page time to load: this is often not necessary but can be helpful depending on the dashboard source). `img2pdf` should be clear.

In the code below, you’ll need to fill in the url you want to scrape (`url_to_scrape`). I’ve pre-filled the name of the saved screenshot to be called 'example.png'.

import asyncio
from pyppeteer import launch

url_to_scrape=''

async def take_screenshot(url, output_path):
    browser = await launch()
    page = await browser.newPage()
    await page.goto(url) 
    await asyncio.sleep(2)  # Waits for (2) seconds
    await page.screenshot({'path': output_path, 'fullPage': True}) 
    await browser.close()

asyncio.get_event_loop().run_until_complete(take_screenshot(url_to_scrape, 'example.png'))

Once we have the screenshot we want, let’s convert it to a .pdf. You can update the pdf_name in the script below if you’d like:

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2025 Lindsay M. Pettingill
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More