From bead7fdf43849ea3e343b2c92ec9775be489db80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Fri, 14 Aug 2026 09:25:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(scraper):=20=E9=A1=B5=E9=9D=A2=E6=8A=93?= =?UTF-8?q?=E5=8F=96=E5=99=A8=E6=94=AF=E6=8C=81=E5=91=98=E5=B7=A5=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=BF=BB=E9=A1=B5(=E4=B9=8B=E5=89=8D=E5=8F=AA?= =?UTF-8?q?=E6=8A=93=E7=AC=AC=E4=B8=80=E9=A1=B510=E4=B8=AA)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yunke-server/scripts/scrape_via_page.py | 39 ++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/yunke-server/scripts/scrape_via_page.py b/yunke-server/scripts/scrape_via_page.py index ef16181..7636b73 100644 --- a/yunke-server/scripts/scrape_via_page.py +++ b/yunke-server/scripts/scrape_via_page.py @@ -209,11 +209,42 @@ class PageScraper: return result; }""") - # Also paginate through staff list if needed - # (for now, first page of 50 should cover most) + # Paginate through ALL staff list pages + all_employees = list(employees) + page = 1 + while await self.click_next_page(): + page += 1 + await self.page.wait_for_timeout(2000) + more = await self.page.evaluate("""() => { + const rows = document.querySelectorAll('.ant-table-row'); + const result = []; + for (const tr of rows) { + const friendLink = tr.querySelector('a[href*="wechatdetail/1/"]'); + const groupLink = tr.querySelector('a[href*="wechatdetail/2/"]'); + if (friendLink) { + const href = friendLink.getAttribute('href'); + const wxId = href.match(/wechatdetail\\/1\\/([^?]+)/)?.[1]; + const friendCount = parseInt(friendLink.textContent) || 0; + const groupHref = groupLink?.getAttribute('href'); + const groupCount = parseInt(groupLink?.textContent) || 0; + result.push({ wxId, friendCount, groupCount, friendHref: href, groupHref }); + } + } + return result; + }""") + all_employees.extend(more) + logger.info(f" staff page {page}: +{len(more)} employees (total: {len(all_employees)})") - logger.info(f"Found {len(employees)} employees with friend links") - return employees + # Dedup by wxId + seen = set() + deduped = [] + for emp in all_employees: + if emp["wxId"] not in seen: + seen.add(emp["wxId"]) + deduped.append(emp) + + logger.info(f"Found {len(deduped)} unique employees with friend links ({page} pages)") + return deduped async def scrape_friends(cookie_str: str, max_employees: int = 100):