fix(xiaohongshu): 话题候选等不到时跳过该标签继续发布

话题依赖小红书联想接口实时返回,网络抖动或无匹配时等不到候选框,会让整条
发布失败。改为 try/except:放宽超时(3s/2s→6s/4s),仍等不到就记 warning、
退格清掉已键入的 #tag 残留文本后 continue。标签为可选增强项,不应阻断主流程。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
智行olo
2026-05-30 19:01:47 -07:00
co-authored by Claude Opus 4.8
parent 99a392af2c
commit 1b36b8bd9b
+19 -8
View File
@@ -400,14 +400,25 @@ class XiaoHongShuBaseUploader(BaseVideoUploader):
await desc.click() await desc.click()
for tag in self.tags: # 循环处理所有 tags for tag in self.tags: # 循环处理所有 tags
await page.keyboard.type("#" + tag, delay=30) # 话题候选下拉框依赖小红书联想接口实时返回,网络抖动/无匹配时会等不到。
await page.locator('#creator-editor-topic-container').wait_for( # 标签是可选增强项:等不到候选框就跳过该标签继续,不让整条发布因此失败。
state="visible", try:
timeout=3000 await page.keyboard.type("#" + tag, delay=30)
) await page.locator('#creator-editor-topic-container').wait_for(
first_item = page.locator('#creator-editor-topic-container .item').first state="visible",
await first_item.wait_for(state="visible", timeout=2000) timeout=6000
await first_item.click() )
first_item = page.locator('#creator-editor-topic-container .item').first
await first_item.wait_for(state="visible", timeout=4000)
await first_item.click()
except Exception as exc:
xiaohongshu_logger.warning(
_msg("🏷️", f"话题『{tag}』未出现候选,跳过该标签继续发布: {exc}")
)
# 清掉已键入但未成词的 "#tag" 文本,避免它残留进正文
for _ in range(len("#" + tag)):
await page.keyboard.press("Backspace")
continue
async def fill_meta(self, page: Page) -> None: async def fill_meta(self, page: Page) -> None:
await self.fill_title(page) await self.fill_title(page)