From 33a3cb3361c6a7df825451fe46dfedc7794e1f21 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Fri, 13 Mar 2026 11:03:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=201.=E5=A2=9E=E5=8A=A0=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E8=87=AA=E5=8A=A8=E5=A1=AB=E5=85=A5=202.?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8=E6=8A=93=E5=8F=96=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=90=8E=E4=B8=8D=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scbank_collector.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/scbank_collector.py b/scbank_collector.py index 558b242..4f78b40 100644 --- a/scbank_collector.py +++ b/scbank_collector.py @@ -11,6 +11,10 @@ class SCBankCollector: # 动态生成文件名: data/raw_YYYYMMDD_HHMMSS.jsonl self.ts_str = datetime.now().strftime("%Y%m%d_%H%M%S") + # 配置账号密码 + self.username = "Lsxd01" + self.password = "Lsxd@2026" + # 确保数据目录存在 if not os.path.exists("data"): os.makedirs("data") @@ -138,9 +142,22 @@ class SCBankCollector: self.log(f"正在打开页面: {self.target_url}") try: self.page.goto(self.target_url) + # 等待跳转到登录页并加载输入框 + try: + self.log("等待登录页面加载...") + self.page.wait_for_selector('input[name="username"]', timeout=10000) + + # 自动填入账号密码 + self.log(f"正在自动填入账号: {self.username}") + self.page.fill('input[name="username"]', self.username) + self.page.fill('input[name="password"]', self.password) + self.log("账号密码已填入") + except Exception as e: + self.log(f"自动填入账号密码失败 (可能已登录或页面结构变化): {e}") + except: pass - self.log(">>> 请在浏览器中完成登录操作 <<<") + self.log(">>> 请在浏览器中完成登录操作 (输入验证码并点击登录) <<<") # 等待 URL 包含 homePage (用户指定) try: self.page.wait_for_url("**/homePage**", timeout=0) @@ -180,8 +197,10 @@ class SCBankCollector: except Exception as e: self.log(f"[FATAL] 脚本异常: {e}") finally: - if self.browser: - self.browser.close() + # 数据抓取完成后,浏览器不退出 + # if self.browser: + # self.browser.close() + self.log("浏览器保持开启状态,请手动关闭。") def _filter_status(self): self.log("正在点击“待发货”标签页")