From c59e3053c4cef266be7f6c5ac37f73e676323507 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Fri, 21 Mar 2025 01:04:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=B9=B6=E4=BC=98=E5=8C=96worker.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除main.py中未使用的环境变量设置代码,减少冗余。在worker.py中新增模拟手机环境的设置,并优化日志输出,使用log.info替代print,提升代码可维护性。 --- main.py | 4 ---- worker.py | 9 ++++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index ddfa219..0ac6774 100644 --- a/main.py +++ b/main.py @@ -24,10 +24,6 @@ options = ChromiumOptions() # 无头模式 # options.headless() -import os -os.environ.setdefault('PYTHONIOENCODING', 'utf-8') -print(os.environ) - browser = Chromium(options) tab = browser.latest_tab diff --git a/worker.py b/worker.py index ec2c673..326fc8b 100644 --- a/worker.py +++ b/worker.py @@ -9,6 +9,12 @@ def run_task(browser, executor, log): "/api" ]) + # 模拟手机 + tab.set.window.size(int(1024 * 1.25), int(768 * 1.25)) + tab.set.user_agent( + ua="Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Mobile Safari/537.36", + platform='android' + ) tab.get(url='http://127.0.0.1:24613') @@ -16,6 +22,7 @@ def run_task(browser, executor, log): if tab.url.endswith("/auth/login"): tab.wait.doc_loaded() + tab.wait(2) tab.actions.move_to("@@t()=input@@type=text").click().type("shikong") tab.actions.move_to("@@t()=input@@type=password").click().type("123+AbC") tab.actions.move_to("@@t()=button@@text():登录").click() @@ -24,4 +31,4 @@ def run_task(browser, executor, log): items = tab.eles("t:body") for item in items: - print(item) \ No newline at end of file + log.info(item) \ No newline at end of file