GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - timf34/Substack2Markdown: Download free and premium Substack posts, saving them as Markdown files. Also generates HTML interfaces to allow you to browse and sort the markdown files for each author.

BranchesTags
Open more actions menu

Latest commit

 

History

143 Commits
143 Commits

Folders and files

NameName
Last commit message
Last commit date
assets
assets
 
 
data
data
 
 
substack_html_pages
substack_html_pages
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
author_template.html
author_template.html
 
 
requirements.txt
requirements.txt
 
 
substack_scraper.py
substack_scraper.py
 
 

Repository files navigation

Substack2Markdown

Substack2Markdown is a Python tool for downloading free and premium Substack posts and saving them as both Markdown and HTML files, and includes a simple HTML interface to browse and sort through the posts. It will save paid for content as long as you're subscribed to that substack.

🆕 @Firevvork has built a web version of this tool at Substack Reader - no installation required! (Works for free Substacks only.)

Substack2Markdown Interface

Once you run the script, it will create a folder named after the substack in /substack_md_files, and then begin to scrape the substack URL, converting the blog posts into markdown files. Once all the posts have been saved, it will generate an HTML file in /substack_html_pages directory that allows you to browse the posts.

You can either hardcode the substack URL and the number of posts you'd like to save into the top of the file, or specify them as command line arguments.

Features

  • Converts Substack posts into Markdown files.
  • Generates an HTML file to browse Markdown files.
  • Supports free and premium content (with subscription).
  • Supports scraping a single post URL directly (for example, /p/my-post).
  • Can download Substack-hosted images locally with --images.
  • The HTML interface allows sorting essays by date or likes.

Installation

Clone the repo and install the dependencies:

git clone https://github.com/yourusername/substack_scraper.git
cd substack_scraper

# # Optinally create a virtual environment
# python -m venv venv
# # Activate the virtual environment
# .\venv\Scripts\activate  # Windows
# source venv/bin/activate  # Linux

pip install -r requirements.txt

For the premium scraper, set your Substack email and password with the SUBSTACK_EMAIL and SUBSTACK_PASSWORD environment variables:

export SUBSTACK_EMAIL="[email protected]"
export SUBSTACK_PASSWORD="your-password"

Alternatively, create a file named config.py in the root of the project containing exactly these two lines (with your own details filled in):

EMAIL = "[email protected]"
PASSWORD = "your-password"

config.py is gitignored, so your credentials will never be committed. The environment variables take precedence over config.py if both are set.

You'll also need Microsoft Edge installed for the Selenium webdriver.

Usage

Specify the Substack URL and the directory to save the posts to:

You can hardcode your desired Substack URL and the number of posts you'd like to save into the top of the file and run:

python substack_scraper.py

For free Substack sites:

python substack_scraper.py --url https://example.substack.com --directory /path/to/save/posts

For premium Substack sites:

python substack_scraper.py --url https://example.substack.com --directory /path/to/save/posts --premium

To scrape a single post directly:

python substack_scraper.py --url https://example.substack.com/p/my-post

To download images locally and rewrite markdown image links:

python substack_scraper.py --url https://example.substack.com --images

To scrape a specific number of posts:

python substack_scraper.py --url https://example.substack.com --directory /path/to/save/posts --number 5

To emit YAML frontmatter (title/subtitle/date/author/image) suitable for MDX sites instead of the default # title / **Likes:** N header:

python substack_scraper.py --url https://example.substack.com --frontmatter mdx

Online Version

For a hassle-free experience without any local setup:

  1. Visit Substack Reader
  2. Enter the Substack URL you want to read or export
  3. Click "Go" to instantly view the content or "Export" to download Markdown files

This online version provides a user-friendly web interface for reading and exporting free Substack articles, with no installation required. However, please note that the online version currently does not support exporting premium content. For full functionality, including premium content export, please use the local script as described above. Built by @Firevvork.

Viewing Markdown Files in Browser

To read the Markdown files in your browser, install the Markdown Viewer browser extension. But note, we also save the files as HTML for easy viewing, just set the toggle to HTML on the author homepage.

Or you can use our Substack Reader online tool, which allows you to read and export free Substack articles directly in your browser. (Note: Premium content export is currently only available in the local script version)

About

Download free and premium Substack posts, saving them as Markdown files. Also generates HTML interfaces to allow you to browse and sort the markdown files for each author.

Topics

htmljavascriptmarkdownpythonscraperseleniumsubstacksubstack-downloadsubstack-scraper-pythonui

Resources

Readme
MIT license
Activity

Stars

546 stars

Watchers

4 watching

Forks

176 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.