|
|
@@ -955,21 +955,39 @@ class FranceVisaKeygen:
|
|
|
time.sleep(4)
|
|
|
|
|
|
# 检查是否有未完成的申请需要编辑,或者新建申请
|
|
|
- btn_add = page.ele('#formAccueilUsager\\:ajouterGroupe') or page.ele('text:Create a new application')
|
|
|
+ btn_add = (
|
|
|
+ page.ele('@id:formAccueilUsager:ajouterGroupe')
|
|
|
+ or page.ele('@name:formAccueilUsager:ajouterGroupe')
|
|
|
+ or page.ele('text:Create a new application')
|
|
|
+ or page.ele('text:Créer une nouvelle demande')
|
|
|
+ )
|
|
|
if btn_add:
|
|
|
logger.info("[Application] 点击新建申请组 (ajouterGroupe)...")
|
|
|
btn_add.click()
|
|
|
time.sleep(3)
|
|
|
|
|
|
- # 如果已经在 step1 或需要编辑进入
|
|
|
+ # 如果未进入 step1,尝试点击已有申请的 Edit/Add 进入
|
|
|
if "step1.xhtml" not in page.url:
|
|
|
- btn_edit = page.ele('css:a[title*="Edit"], a[title*="Modif"]') or page.ele('css:a.ui-commandlink')
|
|
|
+ btn_edit = (
|
|
|
+ page.ele('css:a.btnicone[title*="Edit"]')
|
|
|
+ or page.ele('css:a.btnicone[title*="Modif"]')
|
|
|
+ or page.ele('text:Edit application')
|
|
|
+ or page.ele('text:Add an application')
|
|
|
+ or page.ele('text:Ajouter une demande')
|
|
|
+ )
|
|
|
if btn_edit:
|
|
|
+ logger.info("[Application] 点击编辑/追加申请进入表单...")
|
|
|
btn_edit.click()
|
|
|
time.sleep(3)
|
|
|
|
|
|
+ # 再次确认是否在 step1,若不在则直接导航至 step1.xhtml
|
|
|
+ if "step1.xhtml" not in page.url:
|
|
|
+ page.get(urljoin(BASE_APP_URL, "step1.xhtml"))
|
|
|
+ time.sleep(3)
|
|
|
+
|
|
|
# 填充 Step 1 字段
|
|
|
logger.info(f"[Application] 填充基本信息: 国籍={nationality}, 递签国={deposit_country}, 城市={town}, 护照={passport_no}")
|
|
|
+
|
|
|
# 1. 国籍
|
|
|
page.run_js(f"""
|
|
|
let el = document.querySelector("select[name='formStep1:visas-selected-nationality_input']");
|
|
|
@@ -994,44 +1012,70 @@ class FranceVisaKeygen:
|
|
|
let el = document.querySelector("select[name='formStep1:Visas-selected-deposit-country_input']");
|
|
|
if (el) {{ el.value = '{deposit_country}'; el.dispatchEvent(new Event('change', {{ bubbles: true }})); }}
|
|
|
""")
|
|
|
- time.sleep(2)
|
|
|
+ # 等待递签城市下拉框根据递签国完成 AJAX 级联渲染
|
|
|
+ for _ in range(10):
|
|
|
+ opts_len = page.run_js("""
|
|
|
+ let el = document.querySelector("select[name='formStep1:Visas-selected-deposit-town_input']");
|
|
|
+ return el ? el.options.length : 0;
|
|
|
+ """)
|
|
|
+ if opts_len and opts_len > 1:
|
|
|
+ break
|
|
|
+ time.sleep(1)
|
|
|
|
|
|
# 4. 停留期
|
|
|
page.run_js(f"""
|
|
|
let el = document.querySelector("select[name='formStep1:Visas-selected-stayDuration_input']");
|
|
|
if (el) {{ el.value = '{stay_duration}'; el.dispatchEvent(new Event('change', {{ bubbles: true }})); }}
|
|
|
""")
|
|
|
- time.sleep(2)
|
|
|
+ time.sleep(1)
|
|
|
|
|
|
# 5. 目的地
|
|
|
page.run_js(f"""
|
|
|
let el = document.querySelector("select[name='formStep1:Visas-selected-destination_input']");
|
|
|
if (el && el.options.length > 1) {{
|
|
|
- el.value = '{destination}' || el.options[1].value;
|
|
|
+ let targetVal = '{destination}';
|
|
|
+ let found = Array.from(el.options).some(o => o.value === targetVal);
|
|
|
+ if (found) {{
|
|
|
+ el.value = targetVal;
|
|
|
+ }} else {{
|
|
|
+ el.value = el.options[1].value;
|
|
|
+ }}
|
|
|
el.dispatchEvent(new Event('change', {{ bubbles: true }}));
|
|
|
}}
|
|
|
""")
|
|
|
- time.sleep(2)
|
|
|
+ time.sleep(1)
|
|
|
|
|
|
- # 6. 递签城市
|
|
|
+ # 6. 递签城市 (确保在级联选项就绪后选择)
|
|
|
page.run_js(f"""
|
|
|
let el = document.querySelector("select[name='formStep1:Visas-selected-deposit-town_input']");
|
|
|
if (el && el.options.length > 1) {{
|
|
|
- el.value = '{town}' || el.options[1].value;
|
|
|
+ let targetVal = '{town}';
|
|
|
+ let found = Array.from(el.options).some(o => o.value === targetVal);
|
|
|
+ if (found) {{
|
|
|
+ el.value = targetVal;
|
|
|
+ }} else {{
|
|
|
+ el.value = el.options[1].value;
|
|
|
+ }}
|
|
|
el.dispatchEvent(new Event('change', {{ bubbles: true }}));
|
|
|
}}
|
|
|
""")
|
|
|
- time.sleep(2)
|
|
|
+ time.sleep(1)
|
|
|
|
|
|
# 7. 签发国
|
|
|
page.run_js(f"""
|
|
|
let el = document.querySelector("select[name='formStep1:Visas-selected-authority_input']");
|
|
|
if (el && el.options.length > 1) {{
|
|
|
- el.value = '{authority}' || el.options[1].value;
|
|
|
+ let targetVal = '{authority}';
|
|
|
+ let found = Array.from(el.options).some(o => o.value === targetVal);
|
|
|
+ if (found) {{
|
|
|
+ el.value = targetVal;
|
|
|
+ }} else {{
|
|
|
+ el.value = el.options[1].value;
|
|
|
+ }}
|
|
|
el.dispatchEvent(new Event('change', {{ bubbles: true }}));
|
|
|
}}
|
|
|
""")
|
|
|
- time.sleep(2)
|
|
|
+ time.sleep(1)
|
|
|
|
|
|
# 8. 证件类型
|
|
|
page.run_js(f"""
|
|
|
@@ -1041,7 +1085,7 @@ class FranceVisaKeygen:
|
|
|
el.dispatchEvent(new Event('change', {{ bubbles: true }}));
|
|
|
}}
|
|
|
""")
|
|
|
- time.sleep(2)
|
|
|
+ time.sleep(1)
|
|
|
|
|
|
# 9. 护照号与起止日期
|
|
|
page.run_js(f"""
|
|
|
@@ -1062,7 +1106,7 @@ class FranceVisaKeygen:
|
|
|
el.dispatchEvent(new Event('change', {{ bubbles: true }}));
|
|
|
}}
|
|
|
""")
|
|
|
- time.sleep(2)
|
|
|
+ time.sleep(1)
|
|
|
|
|
|
# 11. 签证目的子项
|
|
|
page.run_js(f"""
|
|
|
@@ -1077,51 +1121,97 @@ class FranceVisaKeygen:
|
|
|
el.dispatchEvent(new Event('change', {{ bubbles: true }}));
|
|
|
}}
|
|
|
""")
|
|
|
- time.sleep(2)
|
|
|
-
|
|
|
- # 12. 点击 Verify
|
|
|
- logger.info("[Application] 提交 Step 1 校验 (Verify)...")
|
|
|
- btn_verif = page.ele('#formStep1\\:btnVerifier') or page.ele('text:Verify')
|
|
|
- if btn_verif:
|
|
|
- btn_verif.click()
|
|
|
- time.sleep(4)
|
|
|
+ time.sleep(1)
|
|
|
|
|
|
- # 13. 点击 Next
|
|
|
- btn_suivant = page.ele('#formStep1\\:btnSuivant')
|
|
|
- if not btn_suivant:
|
|
|
- btn_suivant = page.ele('css:button.primaire')
|
|
|
- if btn_suivant:
|
|
|
- logger.info("[Application] 点击下一步 (Next) 触发护照确认弹窗...")
|
|
|
- btn_suivant.click()
|
|
|
- time.sleep(3)
|
|
|
+ # 12. 校验并点击下一步 (Next)
|
|
|
+ logger.info("[Application] 提交 Step 1 (Next) 触发护照确认弹窗...")
|
|
|
+ clicked = page.run_js("""
|
|
|
+ let btn = document.getElementById('formStep1:btnSuivant') || document.querySelector("button[id*='btnSuivant']");
|
|
|
+ if (btn) { btn.click(); return true; }
|
|
|
+ return false;
|
|
|
+ """)
|
|
|
+ if not clicked:
|
|
|
+ btn_suivant = (
|
|
|
+ page.ele('@id:formStep1:btnSuivant')
|
|
|
+ or page.ele('text:Next')
|
|
|
+ or page.ele('text:Suivant')
|
|
|
+ or page.ele('css:button.primaire')
|
|
|
+ )
|
|
|
+ if btn_suivant:
|
|
|
+ btn_suivant.click()
|
|
|
+ time.sleep(2)
|
|
|
|
|
|
- # 14. 弹窗确认 Yes (formStep1:btnValiderModal)
|
|
|
- logger.info("[Application] 确认护照信息弹窗 (Yes)...")
|
|
|
- page.run_js("""
|
|
|
- let modalBtn = document.getElementById('formStep1:btnValiderModal');
|
|
|
- if (modalBtn) {
|
|
|
- modalBtn.click();
|
|
|
- } else {
|
|
|
+ # 13. 弹窗确认 Yes (formStep1:btnValiderModal)
|
|
|
+ logger.info("[Application] 等待并确认护照信息弹窗 (Yes)...")
|
|
|
+ modal_confirmed = False
|
|
|
+ for _ in range(8):
|
|
|
+ res = page.run_js("""
|
|
|
+ let modalBtn = document.getElementById('formStep1:btnValiderModal');
|
|
|
+ if (modalBtn && modalBtn.offsetParent !== null) {
|
|
|
+ modalBtn.click();
|
|
|
+ return "modal_clicked";
|
|
|
+ }
|
|
|
let btns = Array.from(document.querySelectorAll('.ui-dialog button'));
|
|
|
- let y = btns.find(b => b.innerText.trim().toLowerCase() === 'yes' || b.innerText.trim().toLowerCase() === 'oui');
|
|
|
- if (y) y.click();
|
|
|
- }
|
|
|
- """)
|
|
|
- time.sleep(4)
|
|
|
+ let y = btns.find(b => {
|
|
|
+ let t = b.innerText.trim().toLowerCase();
|
|
|
+ return (t === 'yes' || t === 'oui') && b.offsetParent !== null;
|
|
|
+ });
|
|
|
+ if (y) {
|
|
|
+ y.click();
|
|
|
+ return "dialog_clicked";
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ """)
|
|
|
+ if res:
|
|
|
+ logger.info(f"[Application] 护照确认弹窗点击完成 ({res})")
|
|
|
+ modal_confirmed = True
|
|
|
+ break
|
|
|
+ time.sleep(1)
|
|
|
+
|
|
|
+ # 14. 等待跳转至 Step 2 (确认申请已创建成功入库)
|
|
|
+ logger.info("[Application] 等待申请表创建并确认入库...")
|
|
|
+ for _ in range(8):
|
|
|
+ if "step2.xhtml" in page.url or "accueil.xhtml" in page.url:
|
|
|
+ break
|
|
|
+ time.sleep(1)
|
|
|
|
|
|
# 15. 返回主页提取已生成的 FRA1 申请号
|
|
|
logger.info("[Application] 正在从主页提取 FRA1 申请号...")
|
|
|
page.get(urljoin(BASE_APP_URL, "accueil.xhtml"))
|
|
|
- time.sleep(3)
|
|
|
- accueil_html = page.html
|
|
|
-
|
|
|
- fra_matches = re.findall(r'\b(FRA\d[A-Z0-9_-]+)\b', accueil_html, re.I)
|
|
|
- unique_fra = list(dict.fromkeys([c.upper() for c in fra_matches]))
|
|
|
- fra1_number = unique_fra[0] if unique_fra else None
|
|
|
+
|
|
|
+ fra1_number = None
|
|
|
+ unique_fra = []
|
|
|
+ group_id = None
|
|
|
+
|
|
|
+ for attempt in range(1, 6):
|
|
|
+ time.sleep(2)
|
|
|
+ accueil_html = page.html
|
|
|
+ fra_matches = re.findall(r'\b(FRA\d[A-Z0-9_-]+)\b', accueil_html, re.I)
|
|
|
+ unique_fra = list(dict.fromkeys([c.upper() for c in fra_matches]))
|
|
|
+ if unique_fra:
|
|
|
+ fra1_number = unique_fra[0]
|
|
|
+ grp_match = re.search(r'Group\s+n[°o]?\s*(\d+)', accueil_html, re.I)
|
|
|
+ group_id = grp_match.group(1) if grp_match else None
|
|
|
+ break
|
|
|
+ logger.info(f"[Application] 第 {attempt} 次主页提取暂未匹配到,等待页面刷新...")
|
|
|
|
|
|
- # 提取申请组 ID (Group n°...)
|
|
|
- grp_match = re.search(r'Group\s+n[°o]?\s*(\d+)', accueil_html, re.I)
|
|
|
- group_id = grp_match.group(1) if grp_match else None
|
|
|
+ # 16. 协议层双重保障:若 DOM 提取为空,同步 Cookie 并调用 get_applications()
|
|
|
+ if not fra1_number:
|
|
|
+ logger.info("[Application] 尝试使用 HTTP 协议接口同步提取申请记录...")
|
|
|
+ try:
|
|
|
+ cookies = page.cookies()
|
|
|
+ if isinstance(cookies, list):
|
|
|
+ for c in cookies:
|
|
|
+ self.session.cookies.set(c['name'], c['value'])
|
|
|
+ elif isinstance(cookies, dict):
|
|
|
+ self.session.cookies.update(cookies)
|
|
|
+ self.logged_in = True
|
|
|
+ apps = self.get_applications()
|
|
|
+ if apps and apps[0].get("fra1_number"):
|
|
|
+ fra1_number = apps[0]["fra1_number"]
|
|
|
+ unique_fra = [a["fra1_number"] for a in apps if a.get("fra1_number")]
|
|
|
+ except Exception as ex:
|
|
|
+ logger.warning(f"[Application] 协议层兜底获取异常: {ex}")
|
|
|
|
|
|
logger.info(f"[Application] 提取结果 -> 申请组号: {group_id}, FRA1 申请号: {fra1_number}")
|
|
|
|
|
|
@@ -1431,6 +1521,16 @@ def auto_register(config: Optional[Union[Dict[str, Any], str]] = None, **kwargs)
|
|
|
logger.info(f"[AutoRegister] 正在为账号 {email} 执行自动化填表并获取 FRA1 申请编号...")
|
|
|
app_res = client.fill_step1_and_create_application(applicant_data=cfg)
|
|
|
fra_code = app_res.get("fra1_number")
|
|
|
+ if not fra_code:
|
|
|
+ try:
|
|
|
+ logger.info("[AutoRegister] 页面提取暂未直接返回 FRA1,执行 get_applications() 兜底查询...")
|
|
|
+ apps = client.get_applications()
|
|
|
+ if apps and apps[0].get("fra1_number"):
|
|
|
+ fra_code = apps[0]["fra1_number"]
|
|
|
+ logger.info(f"[AutoRegister] 兜底成功获取到已存在的 FRA1 申请号: {fra_code}")
|
|
|
+ except Exception as ex:
|
|
|
+ logger.warning(f"[AutoRegister] 兜底查询申请号异常: {ex}")
|
|
|
+
|
|
|
if fra_code:
|
|
|
profile["fra1_number"] = fra_code
|
|
|
profile["application_group"] = app_res.get("group_id")
|