feat: 1.增加账号密码自动填入 2.浏览器抓取完成后不退出
This commit is contained in:
parent
cdac3964c7
commit
33a3cb3361
|
|
@ -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("正在点击“待发货”标签页")
|
||||
|
|
|
|||
Loading…
Reference in New Issue