# HotSearch **Repository Path**: scc749/HotSearch ## Basic Information - **Project Name**: HotSearch - **Description**: 这是一个基于Go语言实现的API接口,用于获取多个新闻平台的热搜数据。该接口能够实时抓取各大新闻网站的热搜内容,并返回相关的详细信息,提供统一的API服务。 - **Primary Language**: Go - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2025-05-18 - **Last Updated**: 2026-02-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HotSearch ### 功能概述 这是一个基于Go语言实现的API接口,用于获取多个新闻平台的热搜数据。该接口能够实时抓取各大新闻网站的热搜内容,并返回相关的详细信息,提供统一的API服务。 ### 请求格式 ``` GET http://127.0.0.1:7490/api/news/:source ``` ### 请求参数 | 参数 | 类型 | 说明 | 是否必填 | | ------ | ------ | ------------------------------------------------------------ | -------- | | source | string | 热榜来源平台标识,支持以下值:
`baidu`、`bilibili`、`douyin`、`kuaishou`、`pengpai`、`qqnews`、`sina`、`sougou`、`sspai`、`tieba`、`toutiao`、`weibo`、`zhihu` | 是 | ### 响应示例 #### 成功响应示例: ```json { "code": 0, "data": { "source": "贴吧热议榜", "update_time": "2024-12-04 00:31:39", "hot_list": [ { "index": 1, "title": "新闻标题", "description": "新闻描述", "image": "图片URL", "popularity": "2824170", "url": "新闻链接" }, ... { "index": 30, "title": "新闻标题", "description": "新闻描述", "image": "图片URL", "popularity": "8428", "url": "新闻链接" } ] }, "msg": "success" } ``` **提示**: - 除澎湃热榜返回20条数据外,其他平台返回30条数据。 - 不是所有平台的返回数据都包含 `description`、`image` 和 `popularity` 字段。 #### 失败响应示例: ```json { "code": 7, "data": { "source": "", "update_time": "", "hot_list": null }, "msg": "source not found" } ``` ### 实现细节 #### 响应封装结构 ```go package response import ( "HotSearch/model" "encoding/json" "net/http" ) const ( ERROR = 7 SUCCESS = 0 ) // Response 通用响应结构 type Response struct { Code int `json:"code"` // 响应状态码 Data model.HotSearchData `json:"data"` // 热榜数据 Msg string `json:"msg"` // 响应消息 } // OkWithData 成功响应 func OkWithData(w http.ResponseWriter, data model.HotSearchData) { _ = json.NewEncoder(w).Encode(Response{ Code: SUCCESS, Data: data, Msg: "success", }) } // Failed 错误响应 func Failed(w http.ResponseWriter, err error) { _ = json.NewEncoder(w).Encode(Response{ Code: ERROR, Data: model.HotSearchData{}, Msg: err.Error(), }) } ``` #### 数据模型 ```go package model // HotItem 热点新闻项 type HotItem struct { Index int `json:"index"` // 排名 Title string `json:"title"` // 标题 Description string `json:"description"` // 描述 Image string `json:"image"` // 图片 Popularity string `json:"popularity"` // 热度 URL string `json:"url"` // 链接 } // HotSearchData 热榜数据结构 type HotSearchData struct { Source string `json:"source"` // 数据源 UpdateTime string `json:"update_time"` // 更新时间 HotList []HotItem `json:"hot_list"` // 热搜列表 } ``` ### 支持的热榜来源 下面是支持的 `source` 参数的具体列表,用户可以通过这些值来查询不同平台的热榜: - `baidu`:百度热搜 - `bilibili`:Bilibili 排行榜 - `douyin`:抖音热榜 - `kuaishou`:快手热榜 - `pengpai`:澎湃热榜 - `qqnews`:腾讯热点榜 - `sina`:新浪热榜 - `sougou`:搜狗热搜 - `sspai`:少数派最热 - `tieba`:贴吧热议榜 - `toutiao`:头条热榜 - `weibo`:微博热搜 - `zhihu`:知乎热榜