From 9623e298b73b5b904c7b3ac8b3d811f62027e0ab Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Sat, 9 May 2026 23:19:16 +0100 Subject: [PATCH] =?UTF-8?q?music(chord):=20=E5=85=B3=E6=8E=89=20row=20?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E7=9A=84=20dump=20+=20=E5=99=AA=E9=9F=B3=20l?= =?UTF-8?q?og=EF=BC=8C=E6=90=9C=E7=B4=A2=E9=98=B6=E6=AE=B5=E9=80=89?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E8=B0=B1=E5=B7=B2=E7=BB=8F=E5=A4=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/music/chord/yopu.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/music/chord/yopu.py b/apps/music/chord/yopu.py index a139ecf..b11e617 100644 --- a/apps/music/chord/yopu.py +++ b/apps/music/chord/yopu.py @@ -123,7 +123,8 @@ def find_first_chord_chart(driver, search_url): def select_option_in_row(driver, row_label, button_text, timeout=10): """在 label 含 row_label 的 row 里,点 button.option 文本含 button_text 的按钮。 返回 True 表示点了;False 表示找不到(不算错误,可能是 UI 文案变了)。""" - wait = WebDriverWait(driver, timeout) + # 短 timeout:当前 yopu UI 普遍没这些 row,best-effort 不卡流程 + wait = WebDriverWait(driver, min(timeout, 3)) try: row = wait.until(EC.presence_of_element_located(( By.XPATH, @@ -131,7 +132,7 @@ def select_option_in_row(driver, row_label, button_text, timeout=10): f"and contains(normalize-space(.), '{row_label}')]]" ))) except TimeoutException: - logger.warning("row '%s' not found", row_label) + logger.debug("row '%s' not present (skipped)", row_label) return False buttons = row.find_elements(By.CSS_SELECTOR, "button.option, button") @@ -146,10 +147,9 @@ def select_option_in_row(driver, row_label, button_text, timeout=10): time.sleep(1.2) return True except Exception as e: - logger.warning("click failed in row '%s' / '%s': %s", row_label, button_text, e) + logger.debug("click failed in row '%s' / '%s': %s", row_label, button_text, e) return False - logger.warning("button '%s' not found in row '%s' (had: %s)", - button_text, row_label, [(b.text or '').strip() for b in buttons]) + logger.debug("button '%s' not found in row '%s'", button_text, row_label) return False @@ -288,12 +288,11 @@ def fetch_chord_chart(query: str, output_path: str, *, driver.get(view_url) time.sleep(3) - # 选样式(写死的 MVP 组合) - sheet_ok = select_option_in_row(driver, '谱面样式', sheet_style) - chord_ok = select_option_in_row(driver, '和弦样式', chord_style) - if not (sheet_ok and chord_ok): - # 选不上 = UI 改了,dump 给 debug - _save_debug(driver, 'row-not-found') + # 旧 yopu UI 在 view 页有「谱面样式 / 和弦样式」row 可切; + # 新 yopu 已经下线了这些(要登录 APP 才能切),所以用搜索阶段 + # 选「功能谱」版本绕过去。这里 best-effort 试一下,找不到不算错误。 + select_option_in_row(driver, '谱面样式', sheet_style) + select_option_in_row(driver, '和弦样式', chord_style) # 等内容刷新 time.sleep(1.5)