Substack2Markdown

timf34MIT活跃维护

把 Substack 免费和付费文章批量下载成 Markdown,并生成 HTML 界面按作者浏览排序,方便本地归档和阅读。

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.

v2.1.0发布于 2024-08-10 20:22 UTC545star175fork同步于 2026-11-07 07:34 UTC

怎么上手

从 README 代码块原样提取,可能是其中一种安装方式
git clone https://github.com/yourusername/substack_scraper.git
pip install -r requirements.txt
硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

3 个版本v2.1.0
  1. v2.1.0Substack2Markdown v2.1.0最新正式版2024-08-10 · 2024-08-10 20:22 UTC

    Essays saved directly as HTML as well as Markdown

    View essays directly in HTML or keep viewing them in markdown. We've added a toggle button to the author home page to allow you to switch between HTML or Markdown when viewing essays, which means that you don't need any browser extension to view the lovely formatted essays any more. All while maintaining backwards compatibility.

    New Features

    • Convert markdown files to HTML while maintaining style
    • Toggle between HTML or markdown when viewing essays through the author homepage
  2. v2.0.0Substack2Markdown v2.0.02024-01-28 · 2024-01-28 04:15 UTC
    查看更新说明

    Introducing HTML Interface and Enhanced Metadata Download

    What's New:

    • HTML Interface for browsing and sorting downloaded essays.
    • Metadata (likes, dates, subtitles) now included and sortable.

    Improvements:

    • A modern design with a subtle color scheme.
    • Enhanced file organization for easier navigation.

    Much easier to use when used in combination with Markdown Viewer browser extension

    See the new interface below: screenshot

  3. v1.0.0Substack2Markdown v1.0.02024-01-06 · 2024-01-06 02:16 UTC
    查看更新说明

    Overview

    Substack2Markdown is a Python script designed to scrape articles from a Substack and convert them into markdown files locally. This release introduces two modes of operation: a standard scraper for public articles and a premium scraper for which supports subscribers-only content.

    Features

    • Standard Scraper: Scrapes publicly accessible Substack articles without the need for login credentials.
    • Premium Scraper: Designed for scraping subscriber-only content, requiring Substack login credentials.
    • Selective Scraping: Ability to specify the number of posts to scrape.
    • Custom Save Directory: Option to specify a custom directory for saving the scraped markdown files.
    • Command-Line Interface: Easy-to-use CLI for setting up and running the scraper.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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)