通过 UAPIPRO API 获取知乎热榜数据。
直接通过 exec 调用脚本:
bash
# 获取完整热榜
python3 scripts/zhihu_hot.py
# 获取前10条
python3 scripts/zhihu_hot.py 10
# JSON格式输出
python3 scripts/zhihu_hot.py --json
python3 scripts/zhihu_hot.py 10 --json
GET https://uapis.cn/api/v1/misc/hotboard?type=zhihuAuthorization: Bearer <UAPIPRO_API_KEY>bash
python3 zhihu_hot.py [N] [--json|-j]
N - 返回前N条(不传则返回全部,约50条)--json - 以 JSON 格式输出(用于程序调用)字段说明index排名序号title问题标题url问题链接hot_value热度值,如"634 万热度"extra.desc问题描述/摘要extra.image配图URL(相对路径)extra.label标签,如"新"
python
import subprocess
import json
import os
# 调用脚本获取JSON输出
result = subprocess.run(
["python3", "scripts/zhihu_hot.py", "10", "--json"],
capture_output=True, text=True,
env={**os.environ, "UAPIPRO_API_KEY": os.environ.get("UAPIPRO_API_KEY", "")}
)
data = json.loads(result.stdout)
for item in data["list"]:
print(item["index"], item["title"])
标题:XXX(热度:XXX) 原文链接:XXX
每次回复知乎热榜时统一使用此格式。