Skip to main content

百度贴吧 TextBundle

将百度贴吧的指定帖子下载为 textbundle(内含一个 markdown 文本文件,图片等资源保存在 assets 文件夹中)。

使用 pip 或 pipx 安装:

pip install tiebamd
pipx install tiebamd

使用方法

# 默认只下载楼主发布的楼层
tiebamd https://tieba.baidu.com/p/1766018024

# 包含所有回帖(楼中楼除外)
tiebamd https://tieba.baidu.com/p/1766018024 --repliers

除此之外,还有两个命令行参数可以使用:

--start-fid

本次下载的起点楼层 ID(不是楼层数,是楼层的 HTML 属性 id 所后缀的数字)

--http-proxy

通过指定的 HTTP 代理进行下载

遭遇错误

在下载过程中,可能会遇到一些错误,比如百度拒绝访问。对于已经发现的报错,在程序中已经添加了相关处理代码。 对于短时间内请求过多导致百度拒绝访问的情况(error_code 239103),默认采用等待 3 分钟再继续的策略。 对于其他报错,请记录程序输出的提示,并提交到 issue 方便程序改进。

提示输出样式如下:

xxxx/yyyy: (zzzz)

xxxx 表示帖子 ID,yyyy 表示楼层 ID,zzzz 表示错误代码。

可以将 yyyy 位置所提供的 fid 提供给命令行参数 --start-fid,令程序从中断处继续。不过这不会删除之前已经下载的部分,可能导致下载的文本内容存在重复。

# 这将从目标帖子的第 381 楼开始下载
tiebamd https://tieba.baidu.com/p/1766018024 --start-fid 22754385957

如果反复遇到相同的错误或者开发者无法重现,可以将环境变量 DEBUG 的值设为 1,然后再次运行。这会在当前工作目录下生成 debug_xxx_error.json 文件,记录了几处请求信息,可以将其提交到 issue 方便开发者调试。

# bash/zsh 等 Unix Shell
DEBUG=1 tiebamd https://tieba.baidu.com/p/1766018024
# powershell
$env:DEBUG = 1
tiebamd https://tieba.baidu.com/p/1766018024
# cmd.exe
set DEBUG=1
tiebamd https://tieba.baidu.com/p/1766018024

示例

下面的命令所下载的是 Defanive2 编写,发布在 minecraft 吧的《直播,MC 1.3 原版生存》。包含图片(7000+ 张)共 974 MB 内容,下载总耗时约 20 min,中间中断两次。

tiebamd https://tieba.baidu.com/p/1766018024

0it [00:00, ?it/s]
抓取帖子:minecraft/直播,MC 1.3 原版生存
正在下载 1766018024.textbundle/assets/8b82b9014a90f603c3d8fcd13912b31bb051ed38.jpg: : 86it [00:08, 10.82it/s]
已收集楼层: 125floor [00:07, 15.77floor/s]
docs/result-screenshot.png

下载结果的前几楼

感谢

使用百度贴吧 APP 的 API 接口的代码参考自 https://github.com/cnwangjihe/TiebaBackup。

Metadata

Release files for tiebamd 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tiebamd 0.1.1
File Size Uploaded Provenance Actions
tiebamd-0.1.1.tar.gz 20.7 kB Without provenance Details for tiebamd-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tiebamd 0.1.1
File Interpreter ABI Platform Actions
tiebamd-0.1.1-py3-none-any.whl Python 3 none any Details for tiebamd-0.1.1-py3-none-any.whl

Total release size: 42.2 kB

Release files / tiebamd-0.1.1.tar.gz

Download URL tiebamd-0.1.1.tar.gz
Size 20.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5c803c10d6b5a5be9e2d55cb4c8ac2964e6f7fa2bf889738e5ca483772564060
BLAKE2b-256 checksum
How to use checksums
9076c45e8469d0a664ccf45def834eafd516e914207d3a3cfcd8b5a0b98694c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.0 Windows/10

Release files / tiebamd-0.1.1-py3-none-any.whl

Download URL tiebamd-0.1.1-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67c2d12e4615fdc82b6ff329d394d2114b6dfcaff333818ee2bedaf79c484e8d
BLAKE2b-256 checksum
How to use checksums
292db7dcc83add606870cb3c98ced154dc202c7373087e9440cf34e823214d0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.0 Windows/10

Security for tiebamd 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page