music(chord): 关掉 row 切换的 dump + 噪音 log,搜索阶段选功能谱已经够
deploy music / build-and-deploy (push) Successful in 1m57s
deploy music / build-and-deploy (push) Successful in 1m57s
This commit is contained in:
+10
-11
@@ -123,7 +123,8 @@ def find_first_chord_chart(driver, search_url):
|
|||||||
def select_option_in_row(driver, row_label, button_text, timeout=10):
|
def select_option_in_row(driver, row_label, button_text, timeout=10):
|
||||||
"""在 label 含 row_label 的 row 里,点 button.option 文本含 button_text 的按钮。
|
"""在 label 含 row_label 的 row 里,点 button.option 文本含 button_text 的按钮。
|
||||||
返回 True 表示点了;False 表示找不到(不算错误,可能是 UI 文案变了)。"""
|
返回 True 表示点了;False 表示找不到(不算错误,可能是 UI 文案变了)。"""
|
||||||
wait = WebDriverWait(driver, timeout)
|
# 短 timeout:当前 yopu UI 普遍没这些 row,best-effort 不卡流程
|
||||||
|
wait = WebDriverWait(driver, min(timeout, 3))
|
||||||
try:
|
try:
|
||||||
row = wait.until(EC.presence_of_element_located((
|
row = wait.until(EC.presence_of_element_located((
|
||||||
By.XPATH,
|
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}')]]"
|
f"and contains(normalize-space(.), '{row_label}')]]"
|
||||||
)))
|
)))
|
||||||
except TimeoutException:
|
except TimeoutException:
|
||||||
logger.warning("row '%s' not found", row_label)
|
logger.debug("row '%s' not present (skipped)", row_label)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
buttons = row.find_elements(By.CSS_SELECTOR, "button.option, button")
|
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)
|
time.sleep(1.2)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
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
|
return False
|
||||||
logger.warning("button '%s' not found in row '%s' (had: %s)",
|
logger.debug("button '%s' not found in row '%s'", button_text, row_label)
|
||||||
button_text, row_label, [(b.text or '').strip() for b in buttons])
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -288,12 +288,11 @@ def fetch_chord_chart(query: str, output_path: str, *,
|
|||||||
driver.get(view_url)
|
driver.get(view_url)
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
# 选样式(写死的 MVP 组合)
|
# 旧 yopu UI 在 view 页有「谱面样式 / 和弦样式」row 可切;
|
||||||
sheet_ok = select_option_in_row(driver, '谱面样式', sheet_style)
|
# 新 yopu 已经下线了这些(要登录 APP 才能切),所以用搜索阶段
|
||||||
chord_ok = select_option_in_row(driver, '和弦样式', chord_style)
|
# 选「功能谱」版本绕过去。这里 best-effort 试一下,找不到不算错误。
|
||||||
if not (sheet_ok and chord_ok):
|
select_option_in_row(driver, '谱面样式', sheet_style)
|
||||||
# 选不上 = UI 改了,dump 给 debug
|
select_option_in_row(driver, '和弦样式', chord_style)
|
||||||
_save_debug(driver, 'row-not-found')
|
|
||||||
|
|
||||||
# 等内容刷新
|
# 等内容刷新
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
|
|||||||
Reference in New Issue
Block a user