feat(route/baidu): add BAIDU_COOKIE support and extract shared …#21663
Open
FlanChanXwO wants to merge 10 commits intoDIYgod:masterfrom
Open
feat(route/baidu): add BAIDU_COOKIE support and extract shared …#21663FlanChanXwO wants to merge 10 commits intoDIYgod:masterfrom
FlanChanXwO wants to merge 10 commits intoDIYgod:masterfrom
Conversation
…a routes and implement user post retrieval
… 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
Contributor
|
Successfully generated as following: http://localhost:1200/baidu/tieba/forum/good/孙笑川 - Failed ❌http://localhost:1200/baidu/tieba/post/10620724314 - Failed ❌http://localhost:1200/baidu/tieba/user/斗鱼游戏君 - Failed ❌http://localhost:1200/baidu/tieba/search/反原神 - Failed ❌ |
Contributor
|
Successfully generated as following: http://localhost:1200/baidu/tieba/forum/good/孙笑川 - Failed ❌http://localhost:1200/baidu/tieba/post/10620724314 - Failed ❌http://localhost:1200/baidu/tieba/user/斗鱼游戏君 - Failed ❌http://localhost:1200/baidu/tieba/search/反原神 - Failed ❌ |
…ontent retrieval (#2)
Contributor
|
Successfully generated as following: http://localhost:1200/baidu/tieba/forum/good/孙笑川 - Failed ❌http://localhost:1200/baidu/tieba/post/10620724314 - Failed ❌http://localhost:1200/baidu/tieba/user/斗鱼游戏君 - Failed ❌http://localhost:1200/baidu/tieba/search/反原神 - Failed ❌ |
Contributor
|
Successfully generated as following: http://localhost:1200/baidu/tieba/forum/good/孙笑川 - Failed ❌http://localhost:1200/baidu/tieba/post/10620724314 - Failed ❌http://localhost:1200/baidu/tieba/user/斗鱼游戏君 - Failed ❌http://localhost:1200/baidu/tieba/search/反原神 - Failed ❌ |
TonyRL
reviewed
Apr 14, 2026
Comment on lines
+9
to
+23
| export function parseBaiduCookies(cookieStr: string): Array<{ name: string; value: string; domain: string }> { | ||
| return cookieStr | ||
| .split(';') | ||
| .map((c) => c.trim()) | ||
| .filter((c) => c.length > 0) | ||
| .map((c) => { | ||
| const firstEqualIndex = c.indexOf('='); | ||
| if (firstEqualIndex === -1) { | ||
| return { name: c, value: '', domain: '.tieba.baidu.com' }; | ||
| } | ||
| const name = c.slice(0, firstEqualIndex).trim(); | ||
| const value = c.slice(firstEqualIndex + 1).trim(); | ||
| return { name, value, domain: '.tieba.baidu.com' }; | ||
| }); | ||
| } |
| await page.setCookie(...cookies); | ||
|
|
||
| // 访问目标页面 - 使用更宽松的等待条件 | ||
| await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 60000 }); |
Collaborator
There was a problem hiding this comment.
The puppeteer session will be killed
Lines 154 to 156 in 870a093
|
|
||
| const threadListHTML = load(data)('code[id="pagelet_html_frs-list/pagelet/thread_list"]') | ||
| .contents() | ||
| .filter((e) => e.nodeType === '8'); |
Collaborator
There was a problem hiding this comment.
No page turn. Extract content from the first page only.
Comment on lines
+135
to
+136
| <div dangerouslySetInnerHTML={{ __html: postContent }} /> | ||
| <div dangerouslySetInnerHTML={{ __html: images }} /> |
Collaborator
There was a problem hiding this comment.
Use raw instead instead of dangerouslySetInnerHTML attribute
| <p> | ||
| 楼层:{floor} | ||
| <br /> | ||
| 时间:{timeText} |
Collaborator
There was a problem hiding this comment.
Do not include pubDate in description. It belong to its own dedicated field.
| requestTimeout: toInt(envs.CACHE_REQUEST_TIMEOUT, 60), | ||
| routeExpire: toInt(envs.CACHE_EXPIRE, 5 * 60), // 路由缓存时间,单位为秒 | ||
| contentExpire: toInt(envs.CACHE_CONTENT_EXPIRE, 1 * 60 * 60), // 不变内容缓存时间,单位为秒 | ||
| contentExpire: toInt(envs.CACHE_CONTENT_EXPIRE, 60 * 60), // 不变内容缓存时间,单位为秒 |
Collaborator
There was a problem hiding this comment.
Do not make any changes to the default value.
| | 'BITBUCKET_USERNAME' | ||
| | 'BITBUCKET_PASSWORD' | ||
| | 'BTBYR_HOST' | ||
| | 'BAIDU_COOKIE' |
| /** | ||
| * 解析相对时间(如"回复于4小时前")为实际日期 | ||
| */ | ||
| export function parseRelativeTime(timeStr: string): Date { |
| throw new ConfigNotFoundError('Baidu Tieba RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#baidu">BAIDU_COOKIE</a>'); | ||
| } | ||
|
|
||
| const { getPuppeteerPage } = await import('@/utils/puppeteer'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Involved Issue / 该 PR 相关 Issue
Close #19642
Example for the Proposed Route(s) / 路由地址示例
New RSS Route Checklist / 新 RSS 路由检查表
PuppeteerNote / 说明
概述
本次 PR 为百度贴吧的 4 个路由(
/baidu/tieba/forum、/baidu/tieba/post、/baidu/tieba/search、/baidu/tieba/user)添加了 BAIDU_COOKIE 支持,以应对百度反爬机制的升级。主要改动
从 HTTP 请求迁移到 Puppeteer
got/ofetch直接发送 HTTP 请求获取页面内容新增
common.ts共享模块parseBaiduCookies(): 正确解析包含=字符的 Cookie 值getTiebaPageContent(): 统一的页面获取逻辑,包含 Cookie 注入和安全验证检查normalizeUrl(): 将相对链接转换为绝对地址checkSecurityVerification(): 检测百度安全验证页面并抛出友好错误提示各路由适配
.thread-card选择器改进时间解析
parseRelativeTime()支持更多格式(刚刚、昨天、X天前等)必需配置
以下 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