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:
@@ -400,14 +400,25 @@ class XiaoHongShuBaseUploader(BaseVideoUploader):
|
||||
await desc.click()
|
||||
|
||||
for tag in self.tags: # 循环处理所有 tags
|
||||
await page.keyboard.type("#" + tag, delay=30)
|
||||
await page.locator('#creator-editor-topic-container').wait_for(
|
||||
state="visible",
|
||||
timeout=3000
|
||||
)
|
||||
first_item = page.locator('#creator-editor-topic-container .item').first
|
||||
await first_item.wait_for(state="visible", timeout=2000)
|
||||
await first_item.click()
|
||||
# 话题候选下拉框依赖小红书联想接口实时返回,网络抖动/无匹配时会等不到。
|
||||
# 标签是可选增强项:等不到候选框就跳过该标签继续,不让整条发布因此失败。
|
||||
try:
|
||||
await page.keyboard.type("#" + tag, delay=30)
|
||||
await page.locator('#creator-editor-topic-container').wait_for(
|
||||
state="visible",
|
||||
timeout=6000
|
||||
)
|
||||
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:
|
||||
await self.fill_title(page)
|
||||
|
||||
Reference in New Issue
Block a user