将 policy-radar skill 从 .claude/skills/ 移至 skills/ 顶层目录
- 删除旧的 skills/policy-radar/(仅有旧版 SKILL.md) - 删除 .claude/skills/policy-radar/(含 tools/scrapers.py) - 在 skills/policy-radar/ 重建,包含最新版 SKILL.md + tools/ 消除两个重叠路径,统一使用 skills/policy-radar/ 作为 skill 目录。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -263,69 +263,36 @@ description: 政策雷达 — 从中国政府公开信息源抓取最新政策
|
||||
|
||||
## 5. 抓取工具与方法
|
||||
|
||||
### 5.1 工具选择
|
||||
### 5.1 可复用抓取工具(推荐)
|
||||
|
||||
skill 目录下提供了预构建的 Python 抓取模块 `tools/scrapers.py`,覆盖全部 11 个数据源。**优先使用这些工具,而非临时编写 curl 脚本。**
|
||||
|
||||
```python
|
||||
import sys
|
||||
sys.path.insert(0, '.claude/skills/policy-radar')
|
||||
from tools.scrapers import scrape_list, scrape_article
|
||||
|
||||
# 获取某站点的最新列表
|
||||
items = scrape_list("gov.cn") # 返回 [{title, date, url}, ...]
|
||||
items = scrape_list("pbc") # 央行货币政策/公告
|
||||
items = scrape_list("people") # 人民日报社论
|
||||
|
||||
# 抓取某篇文章正文
|
||||
article = scrape_article("gov.cn", url) # 返回 [{text}, ...]
|
||||
```
|
||||
|
||||
**支持的站点名称:** `gov.cn`, `xinhuanet`, `pbc`, `mof`, `ndrc`, `csrc`, `mofcom`, `people`, `cctv`, `ce`, `scio`
|
||||
|
||||
### 5.2 工具选择
|
||||
|
||||
| 工具 | 适用场景 | 缺点 |
|
||||
|------|----------|------|
|
||||
| **tools/scrapers.py(推荐)** | 直接调用预置抓取器,覆盖11个源 | 网站结构变更时需更新正则 |
|
||||
| WebSearch | 通用搜索,找最新政策链接 | 依赖配额,可能 403 |
|
||||
| WebFetch | 获取单个页面全文 | 依赖配额,部分站点证书问题 |
|
||||
| **curl + python3(推荐)** | 直接 HTTP 请求 + HTML 解析 | 需处理编码和动态页面 |
|
||||
| curl + python3 | 直接 HTTP 请求 + HTML 解析 | 需处理编码和动态页面 |
|
||||
|
||||
**当 WebSearch / WebFetch 不可用时,使用 curl + python3 作为降级方案(本方案已在实际运行中验证可用)。**
|
||||
|
||||
### 5.2 抓取脚本
|
||||
|
||||
#### 5.2.1 获取最新政策列表(gov.cn)
|
||||
|
||||
```bash
|
||||
curl -sL --max-time 15 "https://www.gov.cn/zhengce/" 2>/dev/null | python3 -c "
|
||||
import sys, re
|
||||
html = sys.stdin.read()
|
||||
# 提取最新政策列表
|
||||
items = re.findall(r'<li>\s*<a href=\"([^\"]+)\"[^>]*>\s*([^<]+)\s*</a>\s*<span>\s*([\d-]+)\s*</span>', html)
|
||||
for url, title, date in items:
|
||||
title = title.strip()
|
||||
if title and '2026' in date:
|
||||
print(f'{date} | {title} | {url}')
|
||||
"
|
||||
```
|
||||
|
||||
#### 5.2.2 抓取政策正文(gov.cn)
|
||||
|
||||
```bash
|
||||
curl -sL --max-time 15 "<页面URL>" 2>/dev/null | python3 -c "
|
||||
import sys, re
|
||||
html = sys.stdin.read()
|
||||
paragraphs = re.findall(r'<p[^>]*>(.*?)</p>', html, re.DOTALL)
|
||||
for p in paragraphs:
|
||||
text = re.sub(r'<[^>]+>', '', p).strip()
|
||||
if text and len(text) > 10:
|
||||
print(text)
|
||||
"
|
||||
```
|
||||
|
||||
#### 5.2.3 抓取部委动态列表(以央行为例)
|
||||
|
||||
```bash
|
||||
curl -sL --max-time 15 "https://www.pbc.gov.cn/goutongjiaoliu/113456/113469/index.html" 2>/dev/null | python3 -c "
|
||||
import sys, re
|
||||
html = sys.stdin.read()
|
||||
links = re.findall(r'<a[^>]*href=\"(/goutongjiaoliu/[^\"]+)\"[^>]*>([^<]+)</a>', html)
|
||||
for href, title in links:
|
||||
title = title.strip()
|
||||
if title and len(title) > 5:
|
||||
print(f'{title} | https://www.pbc.gov.cn{href}')
|
||||
"
|
||||
```
|
||||
|
||||
#### 5.2.4 处理 404 / 页面不存在
|
||||
|
||||
gov.cn 的 `/zhengce/content/` 路径下部分文件 ID 不存在(返回"页面不存在")。判断方法:
|
||||
|
||||
```python
|
||||
if "页面不存在" in html or "您访问的页面不存在" in html:
|
||||
# 该 URL 无效,跳过
|
||||
```
|
||||
**当预置工具不可用时,使用 curl + python3 作为降级方案。**
|
||||
|
||||
### 5.3 原文获取质量与降级标注
|
||||
|
||||
@@ -355,17 +322,24 @@ if "页面不存在" in html or "您访问的页面不存在" in html:
|
||||
|
||||
## 6. 数据源 URL 速查
|
||||
|
||||
| 来源 | URL | 内容 |
|
||||
|------|-----|------|
|
||||
| 中国政府网 | https://www.gov.cn/zhengce/ | 国务院政策文件库 |
|
||||
| 国新办 | https://www.scio.gov.cn/xwfbh/ | 新闻发布会文字实录 |
|
||||
| 新华社 | https://www.xinhuanet.com/ | 受权发布 |
|
||||
| 央行 | https://www.pbc.gov.cn/goutongjiaoliu/113456/ | 货币政策 |
|
||||
| 财政部 | https://www.mof.gov.cn/zhengwuxinxi/ | 财政政策 |
|
||||
| 证监会 | https://www.csrc.gov.cn/csrc/c100028/ | 证监会公告 |
|
||||
| 发改委 | https://www.ndrc.gov.cn/xxgk/ | 产业政策 |
|
||||
| 人民日报 | http://www.people.com.cn/ | 社论 |
|
||||
| 央视新闻 | https://news.cctv.com/ | 新闻联播 |
|
||||
| 来源 | URL | 内容 | 工具名 |
|
||||
|------|-----|------|--------|
|
||||
| 中国政府网 | https://www.gov.cn/zhengce/ | 国务院政策文件库 | `gov.cn` |
|
||||
| 新华社 | https://www.news.cn/ | 受权发布/时政 | `xinhuanet` |
|
||||
| 国新办 | https://www.scio.gov.cn/xwfbh/ | 新闻发布会文字实录 | `scio` (镜像: pbc.gov.cn) |
|
||||
| 央行 | https://www.pbc.gov.cn/goutongjiaoliu/113456/ | 货币政策/公告 | `pbc` |
|
||||
| 财政部 | https://www.mof.gov.cn/zhengwuxinxi/ | 财政政策 | `mof` |
|
||||
| 发改委 | https://www.ndrc.gov.cn/xxgk/ | 产业政策/规划 | `ndrc` |
|
||||
| 证监会 | https://www.csrc.gov.cn/csrc/c100028/ | 证监会公告 | `csrc` |
|
||||
| 商务部 | https://www.mofcom.gov.cn/ | 外贸/消费政策 | `mofcom` |
|
||||
| 人民日报 | http://opinion.people.com.cn/ | 社论/评论 | `people` |
|
||||
| 央视新闻 | https://news.cctv.com/ | 新闻联播文字版 | `cctv` |
|
||||
| 经济日报 | http://www.ce.cn/ | 部委政策解读 | `ce` |
|
||||
|
||||
**注意事项:**
|
||||
- 国新办 (scio.gov.cn) 有 JS 反爬挑战,工具使用央行镜像站获取国新办发布会实录
|
||||
- 新华社内容已迁移至 www.news.cn(旧域名 xinhuanet.com 仅有历史内容)
|
||||
- 人民日报社论版使用 opinion.people.com.cn 子域名
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user