knowhow.md 1.42 KB

热点抓取知识库

平台 API 和反爬策略

微博热搜

  • API: https://weibo.com/ajax/statuses/hot (需要登录) 或使用第三方API
  • 替代: https://weibo.com/ajax/statuses/hot/total (热门话题榜)
  • 反爬: User-Agent 伪装,建议添加延迟

百度热搜

  • API: https://top.baidu.com/api? (需要 params)
  • 替代: 爬取 https://top.baidu.com/board?tab=realtime

知乎热榜

  • API: https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=50
  • 反爬: 需要 cookie,可使用公共账号

抖音热榜

  • API: https://www.douyin.com/aweme/v1/web/hot/search/list/
  • 反爬: 需 User-Agent 伪装

B站热门

  • API: https://api.bilibili.com/x/web-interface/popular
  • 反爬: 需 Referer 伪装

数据清洗规则

  1. 去除 HTML 标签: 使用正则 <[^>]+>
  2. 去除多余空白: \s+ →
  3. URL 规范化: 相对路径转为绝对路径
  4. 时间戳标准化: 转为 ISO 8601 格式
  5. 热度值归一化: 数值化处理

输出格式

{
  "trends": [
    {
      "title": "string",
      "url": "string",
      "source": "string",
      "hot_value": number,
      "timestamp": "ISO8601",
      "category": "string"
    }
  ]
}

错误处理

  • 请求超时: 重试 3 次,每次间隔 2 秒
  • 解析失败: 跳过该条,记录日志
  • 网络错误: 返回空列表,标记错误类型