For a long time now, I’ve wanted to export my LiveJournal account to PDF files so that I have a local copy of it. But LiveJournal has no export feature. There are sites like BlogBooker, who (for a fee and my LJ login) will generate PDFs for me; there are also other sites which (if I give them my LJ login) will import my LJ posts and comments. But I don’t trust any of those services to get everything. Plus, I wanted to find a solution on my own.
Attempt #1: use Automator (a macOS tool) to go through the site, scrape the URLs, visit the pages, and print them. And Automator has built-in functions to do all this! Problem is, LJ requires a login for displaying my restricted-access posts, and Automator can’t log in, so it misses a lot of my posts. And Automator insists on doing all the work itself instead of going through Safari. Oh well.
Attempt #2: use Selenium to control Safari to go through the site and print the pages. I’ve used Selenium at work for automated web page tests; it’s a powerful tool. Only, it insists on launching a clean instance of Safari every time (not reusing my login). I’ve tried binding it to my existing Safari instance but that just throws errors. Oh well.
So that’s the approach I decided to go with, and it worked fine.
Here’s the AppleScript I came up with, in case it helps anyone else out there. This works with Safari, in Script Editor on macOS Catalina.