-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
647 additions
and
5 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
# API 文档 | ||
|
||
## 微博 | ||
|
||
### 添加账号 | ||
|
||
- **功能说明** | ||
|
||
用于添加微博网页版账号,cookie从`https://weibo.com/`的请求中获取。 | ||
|
||
- **URL** | ||
|
||
`/weibo/add_account` | ||
|
||
- **Method** | ||
|
||
`POST` | ||
|
||
- **Data Params** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| id | true | string | 账户名(用于管理用户cookie) | | ||
| cookie | true | string | 微博cookie | | ||
|
||
- **Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | true | struct | 数据 | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | | ||
|
||
### 获取账号列表 | ||
|
||
- **URL** | ||
|
||
`/weibo/account_list` | ||
|
||
- **Method** | ||
|
||
`GET` | ||
|
||
- **URL Params** | ||
|
||
None | ||
|
||
- **Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | true | list | [ [账户信息](#账户信息) ] | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | | ||
|
||
#### 账户信息 | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| id | true | string | 账户名(用于管理用户cookie) | | ||
| cookie | true | string | 微博cookie | | ||
| ct | true | int | 创建时间戳 | | ||
| ut | true | int | 更新时间戳 | | ||
| expired | true | int | 0: 有效 1: 过期 (请求失败时自动设为过期) | | ||
|
||
### 获取微博详情 | ||
|
||
- **功能说明** | ||
|
||
由于微博允许游客访问,因此此接口可以不需要添加账号,直接调用。 | ||
|
||
- **URL** | ||
|
||
`/weibo/detail` | ||
|
||
- **Method** | ||
|
||
`GET` | ||
|
||
- **URL Params** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| id | true | string | 微博id,从`https://m.weibo.cn/`找到需要的帖子打开详情页,url中`detail/`后面的数字就是id | | ||
|
||
- **Success Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | true | struct | 数据 | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | | ||
|
||
### 获取微博评论 | ||
|
||
- **URL** | ||
|
||
`/weibo/comments` | ||
|
||
- **Method** | ||
|
||
`GET` | ||
|
||
- **URL Params** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| id | true | string | 微博id,从`https://m.weibo.cn/`找到需要的帖子打开详情页,url中`detail/`后面的数字就是id | | ||
| offset | false | int | 评论翻页偏移量, 默认0 | | ||
| limit | false | int | 评论数量, 默认20 | | ||
|
||
- **Success Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | true | struct | 数据 | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | | ||
|
||
### 获取评论回复 | ||
|
||
- **URL** | ||
|
||
`/weibo/replys` | ||
|
||
- **Method** | ||
|
||
`GET` | ||
|
||
- **URL Params** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| id | true | string | 微博id,从`https://m.weibo.cn/`找到需要的帖子打开详情页,url中`detail/`后面的数字就是id | | ||
| comment_id | true | string | 微博评论id,从评论中获得到的id,例如: 5045096886306039 | | ||
| offset | false | int | 评论翻页偏移量, 默认0 | | ||
| limit | false | int | 评论数量, 默认20 | | ||
|
||
- **Success Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | true | struct | 数据 | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | | ||
|
||
### 关键词搜索微博 | ||
|
||
- **URL** | ||
|
||
`/weibo/search` | ||
|
||
- **Method** | ||
|
||
`GET` | ||
|
||
- **URL Params** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| keyword | true | string | 搜索词 | | ||
| offset | false | int | 搜索翻页偏移量, 默认0 | | ||
| limit | false | int | 结果数量, 默认10 | | ||
|
||
- **Success Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | true | struct | 数据 | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | | ||
|
||
### 微博媒体预览 | ||
|
||
- **功能说明** | ||
|
||
由于微博所有接口返回的媒体资源链接均验证了`referer`,因此不能直接在网页中预览,此接口提供了预览功能,用法为`http://127.0.0.1:8080/weibo/preview?url=xxx`,其中`xxx`替换为媒体资源的地址(请求返回包含参数)即可。 | ||
|
||
- **URL** | ||
|
||
`/weibo/preview` | ||
|
||
- **Method** | ||
|
||
`GET` | ||
|
||
- **URL Params** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| url | true | string | 媒体地址 | | ||
|
||
- **Success Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | true | struct | 数据 | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .detail import request_detail | ||
from .comments import request_comments | ||
from .replys import request_replys | ||
from .search import request_search |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from .common import common_request | ||
|
||
def request_comments(id: str, cookie: str, offset: int = 0, limit: int = 20) -> tuple[dict, bool]: | ||
""" | ||
请求微博获取评论信息 | ||
""" | ||
headers = {"cookie": cookie} | ||
end_length = offset + limit | ||
comments = [] | ||
max_id = 0 | ||
total = 0 | ||
is_end = False | ||
while not is_end and len(comments) < end_length: | ||
params = { | ||
"id": id, | ||
"is_show_bulletin": 2, | ||
"is_mix": 0, | ||
"count": 10, | ||
# "uid": 123, # 可通过profile获取,非强制参数 | ||
"fetch_level": 0, | ||
"locale": "zh-CN", | ||
"max_id": max_id | ||
} | ||
resp, succ = common_request('/ajax/statuses/buildComments', params, headers) | ||
if not succ: | ||
return resp, succ | ||
comments.extend(resp.get('data', [])) | ||
max_id = int(resp.get('max_id', 0)) | ||
total = resp.get('total_number', 0) | ||
is_end = max_id == 0 | ||
|
||
ret = {'total': total, 'comments': comments[offset:end_length]} | ||
return ret, succ |
Oops, something went wrong.