account = $account; $this->password = $password; $this->pageUrl = $pageUrl; $this->unifiedData = new UnifiedScrmData(); } protected function getSpiderConfig() { return [ 'pageUrl' => $this->pageUrl, 'apiUrls' => [self::API_LIST], // 明确指派角色 'listApi' => self::API_LIST, // 必须 'listMethod' => 'POST', 'paginationMode' => self::MODE_UI, 'authActions' => [ // 1. 填入密码:寻找 class 包含 el-message-box__input 下面的任意 input // Node.js 会自动扫描所有匹配项,并只把密码强行注入到那个“肉眼可见”的框里 ['type' => 'vue_fill', 'selector' => '.el-message-box__input input', 'value' => $this->password], // 2. 停顿 500ms,让 Vue 绑定的 v-model 彻底反应过来 ['type' => 'wait', 'ms' => 500], // 3. 点击确认:寻找 MessageBox 底部的蓝色 primary 确认按钮 // 同样利用 vue_click 的可见性过滤,无视隐藏的旧弹窗按钮 ['type' => 'vue_click', 'selector' => '.el-message-box__btns .el-button--primary'], // 4. 等待弹窗淡出,接口开始请求 ['type' => 'wait', 'ms' => 2000] ] ]; } // 只负责解析 List 的总页数 protected function extractListTotalPages($listFirstPageData, $countData = null) { // 只有一页 return 1; } // 没有分页返回空数组 protected function buildListPageParams($page) { return []; } // 提供 List 的下一页按钮信息 protected function getUiPaginationConfig() { return []; } // 清爽至极的数据清洗:详情是详情,列表是列表 protected function parseToUnifiedData($detailData, $allListPagesData) { $unifiedData = $this->unifiedData; $unifiedData->todayNewCount = $allListPagesData[0]['data']['counterWorker']['newTodayFriend']; // 2. 循环合并了所有页数的 List 数组 $count = 0; foreach ($allListPagesData as $pageRaw) { $records = $pageRaw['data']['counterCsAccountVo'] ?? []; foreach ($records as $item) { if(!empty($item['accountLogin'])) { $number = $item['accountLogin'] ?? null; $isOnline = (isset($item['accountStatus']) && $item['accountStatus'] == 1); $count++; $unifiedData->addNumber($number, $isOnline, $item['newTodayFriend']); } } } $unifiedData->total = $count; return $unifiedData; } }