Skip to content

Latest commit

 

History

History
327 lines (247 loc) · 7.15 KB

File metadata and controls

327 lines (247 loc) · 7.15 KB

📋 Scrape-Detail 任务 - 完整流程指南

✅ 第一步:任务已创建

您的 scrape-detail 任务已经成功创建:

Task ID: e1a6f4ca-a9c9-49bb-be87-dd374cb24a40
Platform: tiktok
Action: scrape-detail
Target: https://www.tiktok.com/@zachking
Status: pending

🎯 第二步:等待浏览器扩展自动处理

自动化流程(无需手动操作)

浏览器扩展会:

  1. 轮询任务(每 30 秒)

    GET /api/v1/scraping/tasks/pending
    
  2. 发现您的任务

    {
      "id": "e1a6f4ca-a9c9-49bb-be87-dd374cb24a40",
      "platformId": "tiktok",
      "action": "scrape-detail",
      "target": {"url": "https://www.tiktok.com/@zachking"}
    }
  3. 标记任务为处理中

    POST /api/v1/scraping/tasks/e1a6f4ca.../start
    status: pending → processing
    
  4. 等待您导航到 TikTok

    • 扩展会检测到您在 tiktok.com 域名上
    • 会检查 URL 是否匹配任务目标
  5. 注入 scraper 脚本

    chrome.scripting.executeScript({
      target: { tabId },
      files: ['dist/content/tiktok/scrape.js']
    })
  6. 执行数据提取

    • 提取 profile 数据
    • 提取视频列表
    • 提取详细信息
  7. 提交结果

    POST /api/v1/scraping/tasks/e1a6f4ca.../result
    status: processing → completed
    

👤 第三步:您的操作

方法 A:自动化(推荐)

  1. 确保浏览器扩展已加载(chrome://extensions/)
  2. 打开 TikTok profile
    https://www.tiktok.com/@zachking
    
  3. 等待几秒钟
  4. 扩展会自动处理并提交结果

方法 B:手动测试

如果想手动触发抓取:

  1. 打开 TikTok profile:

    https://www.tiktok.com/@zachking
    
  2. 打开 DevTools (F12)

  3. 在 Console 中执行:

    // 获取任务
    fetch('http://localhost:4000/api/v1/scraping/tasks/pending', {
      headers: {'X-API-Key': 'sk-test-integration-1234567890'}
    }).then(r => r.json()).then(d => {
      const task = d.tasks[0];
      console.log('Task:', task);
    
      // 标记为处理中
      return fetch(`http://localhost:4000/api/v1/scraping/tasks/${task.id}/start`, {
        method: 'POST',
        headers: {'X-API-Key': 'sk-test-integration-1234567890'}
      });
    }).then(() => alert('Task started! Now the scraper can execute.'));
  4. 执行 scraper:

    // 提取 profile 数据
    const profile = await extractProfileData();
    console.log('Profile:', profile);
  5. 提交结果:

    const result = {
      taskId: 'e1a6f4ca-a9c9-49bb-be87-dd374cb24a40',
      platformId: 'tiktok',
      success: true,
      data: { items: [...] },
      timestamp: new Date().toISOString()
    };
    
    fetch(`http://localhost:4000/api/v1/scraping/tasks/e1a6f4ca.../result`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-API-Key': 'sk-test-integration-1234567890'
      },
      body: JSON.stringify(result)
    });

📊 第四步:查看结果

方法 A:Admin Dashboard

  1. 打开: http://localhost:4000/admin.html
  2. 点击 "📊 Results" 标签
  3. 查看最新的抓取结果

方法 B:API 直接查询

curl http://localhost:4000/api/v1/scraping/results \
  -H "X-API-Key: sk-test-integration-1234567890"

方法 C:查询特定任务

curl http://localhost:4000/api/v1/scraping/tasks/e1a6f4ca-a9c9-49bb-be87-dd374cb24a40 \
  -H "X-API-Key: sk-test-integration-1234567890"

🔍 当前系统状态

待处理任务

curl http://localhost:4000/api/v1/scraping/tasks/pending \
  -H "X-API-Key: sk-test-integration-1234567890"

输出:

{
  "tasks": [
    {
      "id": "...",
      "platformId": "tiktok",
      "action": "scrape-detail",
      "target": {"url": "https://www.tiktok.com/@realjayllnn"},
      "status": "pending"
    },
    {
      "id": "e1a6f4ca-a9c9-49bb-be87-dd374cb24a40",
      "platformId": "tiktok",
      "action": "scrape-detail",
      "target": {"url": "https://www.tiktok.com/@zachking"},
      "status": "pending"
    }
  ],
  "count": 2
}

浏览器扩展状态

检查扩展是否运行:

  1. 打开 chrome://extensions/
  2. 找到 "Multi-Platform Scraper"
  3. 点击 "检查视图" (Service Worker 旁边)
  4. 查看 Console

预期日志:

🔍 Checking for pending tasks...
📥 Found 2 pending task(s)

⚡ 快速测试

使用 End-to-End 测试脚本

如果您想自动化测试整个流程:

# 运行完整的测试(会打开浏览器并自动抓取)
node test-tiktok-full-flow.js

这个脚本会:

  1. 创建任务
  2. 启动浏览器
  3. 导航到 TikTok profile
  4. 执行 scraper
  5. 提交结果
  6. 验证完成

📝 scrape-list vs scrape-detail

scrape-list (列表抓取)

  • 目标: 抓取 profile 基本信息
  • 数据: 用户名、显示名、简介、粉丝数、点赞数
  • 适用: 批量抓取多个 KOL 的基本信息

scrape-detail (详情抓取)

  • 目标: 抓取详细信息
  • 数据:
    • 完整 profile 信息
    • 最新视频列表
    • 视频统计(播放量、点赞数、评论数)
    • 每个视频的详细信息
  • 适用: 深度分析特定 KOL

当前实现

当前的 TikTok scraper (scrapeTikTokProfile) 会:

  • ✅ 提取 profile 基本信息
  • ✅ 提取统计数据
  • ✅ 提取播放列表
  • ✅ 计算互动率

对于 scrape-detail,如果需要更详细的数据(如视频列表),可以扩展 scraper。


🎯 下一步建议

选项 1:使用浏览器扩展自动化(最简单)

  1. 确保扩展已加载
  2. 访问: https://www.tiktok.com/@zachking
  3. 等待扩展自动处理
  4. 在 admin page 查看结果

选项 2:手动测试 scraper

  1. 访问: https://www.tiktok.com/@zachking
  2. 打开 DevTools (F12)
  3. 在 Console 中执行 scraper 代码
  4. 查看提取的数据
  5. 手动提交到 API

选项 3:运行自动化测试脚本

node test-tiktok-full-flow.js

选项 4:扩展 scraper 功能(如果需要更多数据)

如果 scrape-detail 需要抓取视频列表等额外数据,我可以帮您扩展 scraper 功能。


📞 现在应该做什么?

最简单的方式

  1. ✅ 确保浏览器扩展已加载并启用
  2. ✅ 打开浏览器访问: https://www.tiktok.com/@zachking
  3. ✅ 等待几秒让扩展处理
  4. ✅ 访问 http://localhost:4000/admin.html 查看结果

就这么简单!浏览器扩展会自动完成所有工作。


🔧 如果遇到问题

扩展没有自动处理?

检查:

  1. 扩展是否已加载 (chrome://extensions/)
  2. API 服务器是否运行 (lsof -ti:4000)
  3. 扩展 Console 是否有错误
  4. 任务是否真的在队列中

任务一直是 pending 状态?

可能原因:

  • 扩展没有轮询到任务
  • URL 不匹配
  • Scraper 执行失败

解决: 查看扩展的 Service Worker Console (chrome://extensions/ → 检查视图)


您想选择哪种方式?我可以帮您:

  1. 测试扩展是否正常工作
  2. 手动执行 scraper 查看数据
  3. 运行自动化测试脚本
  4. 扩展 scraper 功能以支持更多数据