feat: 抽取 Shopee 编辑器模块

新增 app/editor.py,封装商品页打开、登录检测、标题读取写入、封面读取下载、封面上传拖拽、更新按钮点击和 apply_task。

扩展 app/cdp.py 的 host 参数,支持后续按账号端口连接 CDP。

同步任务看板、模块合约、当前状态和进度记录,标记 T-001 完成;记录测试商品标题读写、封面读取与 1_TY030.jpg 上传拖拽验证结果。
This commit is contained in:
chengma
2026-06-26 18:02:57 +08:00
parent ef389b323f
commit 26dac2a718
6 changed files with 457 additions and 18 deletions
+11 -7
View File
@@ -18,12 +18,16 @@ CDP_HOST = os.environ.get("CDP_HOST", "127.0.0.1:9222")
BASE = f"http://{CDP_HOST}"
def http_get(path):
def _base(host=None):
return f"http://{host or CDP_HOST}"
def http_get(path, host=None):
import requests
s = requests.Session()
s.trust_env = False # 忽略环境代理
return s.get(f"{BASE}{path}", timeout=10).json()
return s.get(f"{_base(host)}{path}", timeout=10).json()
class CDP:
@@ -118,9 +122,9 @@ class CDP:
pass
def find_product_tab(item_id):
def find_product_tab(item_id, host=None):
"""在已打开的 tab 里找 URL 同时含 item_id 和 shopee.tw 的页面。"""
for t in http_get("/json"):
for t in http_get("/json", host=host):
if t.get("type") != "page":
continue
url = t.get("url") or ""
@@ -129,9 +133,9 @@ def find_product_tab(item_id):
return None
def create_tab(url):
def create_tab(url, host=None):
"""用 browser 级 Target.createTarget 新建 tab,返回其 page websocket。"""
ver = http_get("/json/version")
ver = http_get("/json/version", host=host)
b = CDP(ver["webSocketDebuggerUrl"])
try:
tid = b.send("Target.createTarget", {"url": url})["targetId"]
@@ -139,7 +143,7 @@ def create_tab(url):
b.close()
end = time.time() + 15
while time.time() < end:
for t in http_get("/json"):
for t in http_get("/json", host=host):
if t.get("id") == tid and t.get("webSocketDebuggerUrl"):
return t["webSocketDebuggerUrl"]
time.sleep(0.5)