Automate screenshots from WEB with Python

I was preparing to make a video about code blocks in motion canvas and I reached the stage where I make screenshots of slides from advanced slides plugin in Obsidian.

To create a video I make a screenshot of each slide and then record voice and add clip on top of it. There were 35 slides to capture as there is no option in Obsidian to export as anything other than PDF which does not change anything.

I found that PySide or PyQt4 but those were outdated and the best option was to use Selenium.

And this was my code.

from selenium import webdriver
from time import sleep

END = 14
URL = "http://localhost:3000/#/"

driver = webdriver.Chrome()

for i in range(1,END+1):
    driver.maximize_window()
    driver.get(URL+str(i))
    sleep(0.6)
    driver.save_screenshot(str(i)+'.png')
    
driver.quit()

First we import selenium and sleep.
Then I added two variables to control how many slides I have in my deck.
And then we take screenshots. It will fire up new browser, maximize it, take a screenshot and change page to next slide. It will wait for 0.6 sec to let transition finish and grab new slide screenshot and so on.

After that you will find all files in the directory you run script from.

You can also watch this in a video in my Youtube Channel!

Thank you!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.