npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@kadaliao/geektime-downloader

v1.0.3

Published

极客时间专栏文章批量下载工具 - 支持一键下载整个专栏为PDF

Readme

极客时间专栏下载器

一键批量下载极客时间专栏文章为 PDF 格式。支持通过 npx 直接运行,无需安装。

✨ 特性

  • 🚀 零安装:支持 npx 直接使用
  • 📦 批量下载:自动获取整个专栏的所有文章
  • 📄 完整内容:自动处理滚动容器,确保 PDF 包含完整内容
  • 🔗 智能合并:自动将所有章节合并为一个 PDF,以专栏名称命名(可选)
  • ⚙️ 灵活配置:命令行参数或配置文件,任选其一
  • 🎨 友好界面:彩色进度提示,实时显示下载状态

🚀 快速开始

🚀 使用方式

方式一:命令行参数方式(推荐)

直接通过命令行参数指定配置,适合一次性使用:

npx @kadaliao/geektime-downloader \
  --url "https://time.geekbang.org/column/article/200822" \
  --cookie "你的cookie字符串"

方式二:配置文件方式

创建配置文件后,直接运行命令即可,适合需要多次使用的情况:

  1. 在项目目录创建 config.json
{
  "cookie": "你的完整 cookie 字符串",
  "columnUrl": "https://time.geekbang.org/column/article/200822"
}
  1. 运行命令:
npx @kadaliao/geektime-downloader

📖 使用说明

获取 Cookie

  1. 浏览器登录极客时间
  2. 打开任意专栏文章
  3. F12 打开开发者工具
  4. 切换到 Network(网络) 标签
  5. 刷新页面,找到任意请求
  6. Request Headers 中复制完整 Cookie

命令行选项

你可以通过以下两种方式运行本工具:

  1. 使用 npx(推荐,无需安装):
npx @kadaliao/geektime-downloader [选项]
  1. 或者全局安装后使用:
# 安装
npm install -g @kadaliao/geektime-downloader

# 使用
geektime-dl [选项]

可用选项:

  -V, --version          显示版本号
  -u, --url <url>        专栏文章URL(任意一篇)
  -c, --cookie <cookie>  Cookie字符串(用于认证)
  -o, --output <dir>     输出目录 (默认: "./downloads")
  --headless <boolean>   无头模式 (默认: true)
  --concurrency <number> 并发下载数量 (默认: 5)
  --delay <ms>           每篇文章间延迟(ms) (默认: 2000)
  --dry-run              预览模式,只显示文章列表
  --limit <number>       限制下载数量(测试用)
  --no-merge             禁用PDF合并(默认会合并所有文章为一个PDF)
  -h, --help             显示帮助

使用示例

预览文章列表

npx @kadaliao/geektime-downloader \
  -u "https://time.geekbang.org/column/article/200822" \
  -c "your_cookie" \
  --dry-run

测试下载

npx @kadaliao/geektime-downloader \
  -u "https://time.geekbang.org/column/article/200822" \
  -c "your_cookie" \
  --limit 2

下载整个专栏

npx @kadaliao/geektime-downloader \
  -u "https://time.geekbang.org/column/article/200822" \
  -c "your_cookie"

自定义输出目录

npx @kadaliao/geektime-downloader \
  -u "https://..." \
  -c "..." \
  --output ~/Documents/极客时间

禁用 PDF 合并(仅保留单独章节)

npx @kadaliao/geektime-downloader \
  -u "https://..." \
  -c "..." \
  --no-merge

📁 输出文件

下载完成后,会在输出目录生成以下文件:

单独章节 PDF(始终生成)

001_开篇词___想吃透架构?你得看看真实、接地气的架构案例.pdf
002_01___架构的本质:如何打造一个有序的系统?.pdf
003_02___业务架构:作为开发,你真的了解业务吗?.pdf
  • 三位数字编号保持文章顺序
  • 自动清理非法字符
  • 限制文件名长度

合并后的 PDF(默认生成)

专栏名称.pdf
  • 默认会将所有章节合并为一个完整的 PDF 文件
  • 文件名为专栏的标题(自动从 API 获取)
  • 包含所有成功下载的章节,按顺序排列
  • 如不需要合并版本,使用 --no-merge 选项

⚙️ 配置方式

优先级

命令行参数 > 配置文件

配置文件示例

创建 config.json(可选):

{
  "cookie": "你的完整 cookie 字符串",
  "columnUrl": "https://time.geekbang.org/column/article/xxxxx"
}

注意

  • Cookie 必须完整,包含所有认证信息
  • columnUrl 可以是专栏任意一篇文章的 URL
  • Cookie 有过期时间,失败时请重新获取
  • 配置文件完全可选,也可纯命令行使用

🐛 常见问题

Playwright 浏览器未安装?

如果遇到 "Executable doesn't exist" 错误,说明 Playwright 浏览器未安装。

方式一:自动安装(推荐)

# 全局安装会自动安装浏览器
npm install -g @kadaliao/geektime-downloader

方式二:手动安装浏览器

# 只安装 Chromium
npx playwright install chromium

# 或安装浏览器及系统依赖(Linux/Mac)
npx playwright install chromium --with-deps

注意:使用 npx 直接运行时,可能需要先手动安装浏览器。为了更好的体验,建议全局安装。

Cookie 和 URL 必须通过命令行传吗?

不是。三种方式任选:

  1. 纯命令行npx @kadaliao/geektime-downloader -u "..." -c "..."
  2. 配置文件:创建 config.json 后直接运行
  3. 混合使用:命令行参数会覆盖配置文件

Cookie 过期了怎么办?

重新获取 Cookie 并更新:

  • 命令行方式:-c "新cookie"
  • 配置文件方式:更新 config.json

PDF 内容不完整?

增加页面加载延迟:

npx @kadaliao/geektime-downloader -u "..." -c "..." --delay 5000

如何下载多个专栏?

每次运行下载一个,只需更改 URL:

npx @kadaliao/geektime-downloader -u "专栏A的URL" -c "..."
npx @kadaliao/geektime-downloader -u "专栏B的URL" -c "..."

🛠 本地开发

# 克隆项目
git clone https://github.com/yourusername/geektime-downloader.git
cd geektime-downloader

# 安装依赖
npm install

# 安装浏览器
npx playwright install chromium

# 本地测试
npm link
geektime-dl --help

📝 项目结构

geektime-downloader/
├── download.js           # 主程序
├── package.json          # npm 配置
├── config.example.json   # 配置模板
├── README.md             # 使用文档
├── PUBLISH.md            # 发布指南(维护者)
└── .gitignore            # Git 忽略规则

🎯 技术栈

  • Playwright: 浏览器自动化
  • Commander: 命令行解析
  • Chalk: 彩色输出
  • Ora: 进度提示
  • pdf-lib: PDF 文档操作和合并

📄 License

MIT

⚠️ 免责声明

本工具仅供个人学习使用,请勿用于商业用途。下载内容版权归极客时间所有,请遵守相关法律法规。