Skip to content

feat(route/baidu): add BAIDU_COOKIE support and extract shared …#21663

Open
FlanChanXwO wants to merge 10 commits intoDIYgod:masterfrom
FlanChanXwO:master
Open

feat(route/baidu): add BAIDU_COOKIE support and extract shared …#21663
FlanChanXwO wants to merge 10 commits intoDIYgod:masterfrom
FlanChanXwO:master

Conversation

@FlanChanXwO
Copy link
Copy Markdown

@FlanChanXwO FlanChanXwO commented Apr 8, 2026

Involved Issue / 该 PR 相关 Issue

Close #19642

Example for the Proposed Route(s) / 路由地址示例

/baidu/tieba/forum/good/孙笑川
/baidu/tieba/post/10620724314
/baidu/tieba/user/斗鱼游戏君
/baidu/tieba/search/反原神

New RSS Route Checklist / 新 RSS 路由检查表

  • New Route / 新的路由
  • Anti-bot or rate limit / 反爬/频率限制
    • If yes, do your code reflect this sign? / 如果有, 是否有对应的措施?
  • Date and time / 日期和时间
    • Parsed / 可以解析
    • Correct time zone / 时区正确
  • New package added / 添加了新的包
  • Puppeteer

Note / 说明

概述

本次 PR 为百度贴吧的 4 个路由(/baidu/tieba/forum/baidu/tieba/post/baidu/tieba/search/baidu/tieba/user)添加了 BAIDU_COOKIE 支持,以应对百度反爬机制的升级。

主要改动

  1. 从 HTTP 请求迁移到 Puppeteer

    • 原有的路由使用 got/ofetch 直接发送 HTTP 请求获取页面内容
    • 由于百度贴吧启用 JavaScript 渲染和反爬验证,原有方式已无法获取有效数据
    • 现改为使用 Puppeteer 操控无头浏览器访问页面,可绕过反爬机制并正确获取 Vue 渲染的内容
  2. 新增 common.ts 共享模块

    • parseBaiduCookies(): 正确解析包含 = 字符的 Cookie 值
    • getTiebaPageContent(): 统一的页面获取逻辑,包含 Cookie 注入和安全验证检查
    • normalizeUrl(): 将相对链接转换为绝对地址
    • checkSecurityVerification(): 检测百度安全验证页面并抛出友好错误提示
  3. 各路由适配

    • forum: 支持并发获取多页内容,自动去重,优化等待策略
    • post: 保留富文本内容(链接、表情等),添加楼层信息,生成直达回复链接
    • search: 规范搜索结果链接为绝对地址
    • user: 适配新版用户主页结构,使用 .thread-card 选择器
  4. 改进时间解析

    • parseRelativeTime() 支持更多格式(刚刚、昨天、X天前等)
    • 添加日期有效性检查,避免输出 Invalid Date

必需配置

以下 4 个路由现在必须配置 BAIDU_COOKIE 才能使用:

路由 示例
/baidu/tieba/forum/:kw /baidu/tieba/forum/女图
/baidu/tieba/post/:id /baidu/tieba/post/686961453
/baidu/tieba/search/:qw /baidu/tieba/search/neuro
/baidu/tieba/user/:uid /baidu/tieba/user/斗鱼游戏君

配置方法

在环境变量或 .env 文件中设置:

BAIDU_COOKIE=BDUSS=your_bduss_value;other_cookie=value

FlanChanXwO and others added 8 commits April 8, 2026 17:36
… handling in forum, post, search, and user routes
… formatting

- Refactor parseBaiduCookies function to use chained array methods for better readability
- Simplify cookie parsing by trimming and filtering empty strings before mapping
- Remove redundant comments in common.ts and post.tsx files
- Improve code formatting by removing excessive blank lines
- Maintain same functionality while enhancing code maintainability
…utilities Add common.ts for cookie parsing, page retrieval, security check and URL normalization. Refactor forum, post, search and user routes to use shared utilities. Preserve rich text content in post replies. Support direct reply links. Fix cookie value parsing for cookies containing '=' character.

Route/baidu
- Remove trailing whitespace from empty lines
- Ensure consistent line endings in utility functions
# Conflicts:
#	lib/routes/baidu/tieba/utils.ts
@github-actions github-actions bot added the route label Apr 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Successfully generated as following:

http://localhost:1200/baidu/tieba/forum/good/孙笑川 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/forum/good/:kw/:cid?/:sortBy?
Full Route: /baidu/tieba/forum/good/孙笑川
Node Version: v24.14.1
Git Hash: 4e7e83d3
http://localhost:1200/baidu/tieba/post/10620724314 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/post/:id
Full Route: /baidu/tieba/post/10620724314
Node Version: v24.14.1
Git Hash: 4e7e83d3
http://localhost:1200/baidu/tieba/user/斗鱼游戏君 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/user/:uid
Full Route: /baidu/tieba/user/斗鱼游戏君
Node Version: v24.14.1
Git Hash: 4e7e83d3
http://localhost:1200/baidu/tieba/search/反原神 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/search/:qw/:routeParams?
Full Route: /baidu/tieba/search/反原神
Node Version: v24.14.1
Git Hash: 4e7e83d3

@github-actions github-actions bot added auto: not ready to review Users can't get the RSS feed output according to automated testing results and removed auto: not ready to review Users can't get the RSS feed output according to automated testing results labels Apr 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Successfully generated as following:

http://localhost:1200/baidu/tieba/forum/good/孙笑川 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/forum/good/:kw/:cid?/:sortBy?
Full Route: /baidu/tieba/forum/good/孙笑川
Node Version: v24.14.1
Git Hash: 4e7e83d3
http://localhost:1200/baidu/tieba/post/10620724314 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/post/:id
Full Route: /baidu/tieba/post/10620724314
Node Version: v24.14.1
Git Hash: 4e7e83d3
http://localhost:1200/baidu/tieba/user/斗鱼游戏君 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/user/:uid
Full Route: /baidu/tieba/user/斗鱼游戏君
Node Version: v24.14.1
Git Hash: 4e7e83d3
http://localhost:1200/baidu/tieba/search/反原神 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/search/:qw/:routeParams?
Full Route: /baidu/tieba/search/反原神
Node Version: v24.14.1
Git Hash: 4e7e83d3

@github-actions github-actions bot added auto: not ready to review Users can't get the RSS feed output according to automated testing results and removed auto: not ready to review Users can't get the RSS feed output according to automated testing results labels Apr 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Successfully generated as following:

http://localhost:1200/baidu/tieba/forum/good/孙笑川 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/forum/good/:kw/:cid?/:sortBy?
Full Route: /baidu/tieba/forum/good/孙笑川
Node Version: v24.14.1
Git Hash: 9d3cb86d
http://localhost:1200/baidu/tieba/post/10620724314 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/post/:id
Full Route: /baidu/tieba/post/10620724314
Node Version: v24.14.1
Git Hash: 9d3cb86d
http://localhost:1200/baidu/tieba/user/斗鱼游戏君 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/user/:uid
Full Route: /baidu/tieba/user/斗鱼游戏君
Node Version: v24.14.1
Git Hash: 9d3cb86d
http://localhost:1200/baidu/tieba/search/反原神 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/search/:qw/:routeParams?
Full Route: /baidu/tieba/search/反原神
Node Version: v24.14.1
Git Hash: 9d3cb86d

@github-actions github-actions bot added auto: not ready to review Users can't get the RSS feed output according to automated testing results and removed auto: not ready to review Users can't get the RSS feed output according to automated testing results labels Apr 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Successfully generated as following:

http://localhost:1200/baidu/tieba/forum/good/孙笑川 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/forum/good/:kw/:cid?/:sortBy?
Full Route: /baidu/tieba/forum/good/孙笑川
Node Version: v24.14.1
Git Hash: b2b46591
http://localhost:1200/baidu/tieba/post/10620724314 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/post/:id
Full Route: /baidu/tieba/post/10620724314
Node Version: v24.14.1
Git Hash: b2b46591
http://localhost:1200/baidu/tieba/user/斗鱼游戏君 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/user/:uid
Full Route: /baidu/tieba/user/斗鱼游戏君
Node Version: v24.14.1
Git Hash: b2b46591
http://localhost:1200/baidu/tieba/search/反原神 - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>ConfigNotFoundError: Baidu Tieba RSS is disabled due to the lack of &lt;a href=&quot;https://docs.rsshub.app/deploy/config#baidu&quot;&gt;BAIDU_COOKIE&lt;/a&gt;
Route: /baidu/tieba/search/:qw/:routeParams?
Full Route: /baidu/tieba/search/反原神
Node Version: v24.14.1
Git Hash: b2b46591

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto: not ready to review Users can't get the RSS feed output according to automated testing results route

Projects

None yet

Development

Successfully merging this pull request may close these issues.

百度精品帖子403

1 participant