How to Find Any Substack Newsletter's Best Posts with Python (2026)

How to Find Any Substack Newsletter’s Best Posts with Python (2026)

每个 Substack 时事通讯都有一些文章获得的赞、评论和转发远超其他内容。这些文章揭示了读者真正想要的东西。在本教程中,你将通过大约 15 行代码,将任何时事通讯的所有文章提取到 Python 中并进行排名。你将获得每篇文章的以下信息:标题、副标题、日期和作者;点赞数、评论数、转发数和字数;是否为付费内容;免费文章的全文(非常适合研究或大语言模型数据集)。免责声明:本文使用的爬虫由我开发。它读取的是 Substack 的公开数据,因此你不需要登录,也不需要 Substack 的 API 密钥。

Setup (2 minutes)

Create a free account at apify.com. The free plan includes monthly credits, enough to follow this tutorial. Copy your API token from Settings → API & Integrations in the Apify Console. Install the client and save the token as an environment variable: pip install "apify-client>=3" export APIFY_TOKEN="your_token_here"

设置(2 分钟)

在 apify.com 创建一个免费账户。免费套餐包含每月额度,足以完成本教程。从 Apify 控制台的“设置”→“API 和集成”中复制你的 API 令牌。安装客户端并将令牌保存为环境变量: pip install "apify-client>=3" export APIFY_TOKEN="your_token_here"

Get the top posts of a newsletter

This gets the 20 most popular posts of Lenny’s Newsletter. It works with name.substack.com addresses and with custom domains.

import os
from apify_client import ApifyClient
client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("neronbaez/substack-scraper").call(run_input={
    "publications": ["lennysnewsletter.com"],
    "sort": "top", # "top" = most popular, "new" = latest
    "maxPostsPerPublication": 20,
    "includeContent": True, # full text of free posts
})
posts = list(client.dataset(run.default_dataset_id).iterate_items())
for p in posts:
    print(f'{p["likes"]:>5} likes | {p["comments"]:>3} comments | '
          f'{p["wordCount"]:>5} words | {p["title"]}')

获取时事通讯的热门文章

这段代码可以获取 Lenny’s Newsletter 最受欢迎的 20 篇文章。它适用于 name.substack.com 地址以及自定义域名。

import os
from apify_client import ApifyClient
client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("neronbaez/substack-scraper").call(run_input={
    "publications": ["lennysnewsletter.com"],
    "sort": "top", # "top" = 最受欢迎, "new" = 最新
    "maxPostsPerPublication": 20,
    "includeContent": True, # 免费文章的全文
})
posts = list(client.dataset(run.default_dataset_id).iterate_items())
for p in posts:
    print(f'{p["likes"]:>5} 点赞 | {p["comments"]:>3} 评论 | '
          f'{p["wordCount"]:>5} 字数 | {p["title"]}')

Each post comes back as a JSON object like this one (trimmed):

{
  "title": "How to tell if a startup has a moat",
  "url": "https://www.lennysnewsletter.com/p/how-to-tell-if-a-startup-has-a-moat",
  "postDate": "2026-10-13T12:45:41.160Z",
  "isPaid": true,
  "likes": 311,
  "comments": 2,
  "restacks": 11,
  "wordCount": 4153,
  "authors": [{"name": "Dan Hockenmaier", "handle": "danhock"}]
}

每篇文章都会以 JSON 对象的形式返回,如下所示(已精简):

{
  "title": "如何判断一家初创公司是否有护城河",
  "url": "https://www.lennysnewsletter.com/p/how-to-tell-if-a-startup-has-a-moat",
  "postDate": "2026-10-13T12:45:41.160Z",
  "isPaid": true,
  "likes": 311,
  "comments": 2,
  "restacks": 11,
  "wordCount": 4153,
  "authors": [{"name": "Dan Hockenmaier", "handle": "danhock"}]
}

Find what works: free vs paid, short vs long

With the posts in a list, two quick questions are one line each:

from statistics import mean
free = [p["likes"] for p in posts if not p["isPaid"]]
paid = [p["likes"] for p in posts if p["isPaid"]]
print("avg likes free:", round(mean(free)) if free else "-")
print("avg likes paid:", round(mean(paid)) if paid else "-")

long_posts = [p["likes"] for p in posts if p["wordCount"] > 2500]
short_posts = [p["likes"] for p in posts if p["wordCount"] <= 2500]
print("avg likes long:", round(mean(long_posts)) if long_posts else "-")
print("avg likes short:", round(mean(short_posts)) if short_posts else "-")

Run it on two or three newsletters in your niche and you will quickly see which formats and topics get the most engagement.

找出有效内容:免费与付费,短文与长文

将文章放入列表后,只需一行代码即可回答两个快速问题:

from statistics import mean
free = [p["likes"] for p in posts if not p["isPaid"]]
paid = [p["likes"] for p in posts if p["isPaid"]]
print("免费平均点赞数:", round(mean(free)) if free else "-")
print("付费平均点赞数:", round(mean(paid)) if paid else "-")

long_posts = [p["likes"] for p in posts if p["wordCount"] > 2500]
short_posts = [p["likes"] for p in posts if p["wordCount"] <= 2500]
print("长文平均点赞数:", round(mean(long_posts)) if long_posts else "-")
print("短文平均点赞数:", round(mean(short_posts)) if short_posts else "-")

在你的领域中选择两到三个时事通讯运行此代码,你很快就能看出哪些格式和主题获得的互动最多。

Going further

Read the comments. Set “includeComments”: True and each comment comes back as its own item with text, author, likes and date. That is the fastest way to learn what readers ask for. Compare newsletters. Put several in “publications” (for example [“lennysnewsletter.com”, “astralcodexten.com”]) and group the results by the publication field. Build a dataset. With “sort”: “new” and a higher maxPostsPerPublication, you get a clean archive of full-text posts for search or RAG. Only free posts include the full text; paid posts include a preview. Cost. You pay per result: $0.002 per post and $0.0005 per comment, so the latest 100 posts of a newsletter cost $0.20.

深入探索

阅读评论。设置 “includeComments”: True,每条评论都会作为单独的项目返回,包含文本、作者、点赞数和日期。这是了解读者需求最快的方法。比较时事通讯。在 “publications” 中放入多个地址(例如 [“lennysnewsletter.com”, “astralcodexten.com”]),并按 publication 字段对结果进行分组。构建数据集。通过设置 “sort”: “new” 和更高的 maxPostsPerPublication,你可以获得用于搜索或 RAG 的全文文章存档。只有免费文章包含全文;付费文章仅包含预览。成本。按结果付费:每篇文章 0.002 美元,每条评论 0.0005 美元,因此获取某时事通讯的最新 100 篇文章仅需 0.20 美元。

Wrap-up

You now have any newsletter’s posts as data, ranked by what readers liked. You can also run the Substack Scraper from the browser without code and export to CSV or Excel. If you need a field or filter it doesn’t have, open an issue on the Actor page and I’ll add it. Which newsletter would you analyze first? Tell me in the comments.

总结

现在,你已经将任何时事通讯的文章转化为数据,并按读者的喜爱程度进行了排名。你也可以在浏览器中无需代码运行 Substack Scraper,并导出为 CSV 或 Excel 文件。如果你需要当前没有的字段或过滤器,请在 Actor 页面提交 issue,我会将其添加进去。你会首先分析哪份时事通讯?在评论区告诉我吧。