From d8897f893af8638df7ecfb067294c853a8cd0d5f Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Wed, 7 Jan 2026 13:21:19 +0800 Subject: [PATCH] Expand KDocs QR detection --- services/kdocs_uploader.py | 66 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/services/kdocs_uploader.py b/services/kdocs_uploader.py index 4c80e3b..751d350 100644 --- a/services/kdocs_uploader.py +++ b/services/kdocs_uploader.py @@ -307,6 +307,14 @@ class KDocsUploader: "canvas[class*='qr']", "svg", "div[role='img']", + "div[class*='qr']", + "div[id*='qr']", + "div[class*='qrcode']", + "div[id*='qrcode']", + "div[class*='wechat']", + "div[class*='weixin']", + "div[class*='wx']", + "img[src*='wx']", ] best = None best_score = None @@ -326,10 +334,10 @@ class KDocsUploader: continue width = box.get("width", 0) height = box.get("height", 0) - if width < 120 or height < 120 or width > 420 or height > 420: + if width < 80 or height < 80 or width > 520 or height > 520: continue aspect_diff = abs(width - height) - if aspect_diff > 40: + if aspect_diff > 80: continue score = aspect_diff + abs(width - 260) + abs(height - 260) if best_score is None or score < best_score: @@ -337,6 +345,41 @@ class KDocsUploader: best = el except Exception: continue + if best: + return best + + handle = None + try: + handle = frame.evaluate_handle( + """() => { + const patterns = [/qr/i, /qrcode/i, /weixin/i, /wechat/i, /wx/i, /data:image/i]; + const elements = Array.from(document.querySelectorAll('*')); + for (const el of elements) { + const style = window.getComputedStyle(el); + const bg = style.backgroundImage || ''; + if (!bg || bg === 'none') continue; + if (!patterns.some((re) => re.test(bg))) continue; + const rect = el.getBoundingClientRect(); + if (!rect.width || !rect.height) continue; + if (rect.width < 80 || rect.height < 80 || rect.width > 520 || rect.height > 520) continue; + const diff = Math.abs(rect.width - rect.height); + if (diff > 80) continue; + return el; + } + return null; + }""" + ) + element = handle.as_element() if handle else None + if element: + return element + except Exception: + pass + finally: + try: + if handle: + handle.dispose() + except Exception: + pass return best def _capture_dialog_image(self, page) -> Optional[bytes]: @@ -398,13 +441,30 @@ class KDocsUploader: self._ensure_login_dialog() qr_image = None - for _ in range(5): + for _ in range(10): qr_image = self._capture_qr_image() if qr_image: break time.sleep(1) if not qr_image: self._last_error = "二维码获取失败" + try: + pages = self._iter_pages() + page_urls = [getattr(p, "url", "") for p in pages] + logger.warning(f"[KDocs] 二维码未捕获,页面: {page_urls}") + ts = int(time.time()) + saved = [] + for idx, page in enumerate(pages[:3]): + try: + path = f"data/kdocs_debug_{ts}_{idx}.png" + page.screenshot(path=path, full_page=True) + saved.append(path) + except Exception: + continue + if saved: + logger.warning(f"[KDocs] 已保存调试截图: {saved}") + except Exception: + pass return {"success": False, "error": self._last_error} self._last_qr_image = qr_image