ygp-gdzwfw-gov-cn/README.md

97 lines
3.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 广东省公共资源交易平台爬虫
本项目是一个 Python 爬虫程序,用于抓取 [广东省公共资源交易平台](https://ygp.gdzwfw.gov.cn/#/44/jygg) 的中标结果公告。
## 功能特性
- **关键字过滤**:自动筛选标题中包含“中标结果”的公告。
- **日期过滤**:支持指定开始和结束日期,默认为抓取当天数据。
- **自动分页**:自动处理多页数据抓取。
- **动态构造 URL**:根据接口返回字段自动生成可直接访问的详情页链接。
- **纯 HTTP 请求**:直接使用 aiohttp 调用官方 API无需浏览器轻量高效。
- **CSV 实时保存**:数据实时保存到 CSV 文件,同时输出到终端。
- **自定义输出路径**:支持通过参数指定输出文件路径。
- **增量爬取**:支持从已有 CSV 文件自动计算时间范围,只抓取新数据,避免重复。
- **数据排序**:新数据在前,旧数据在后,按发布时间倒序排列。
## 环境要求
- Python 3.8+
## 安装步骤
1. **克隆项目并进入目录**
```bash
cd ygp-gdzwfw-gov-cn
```
2. **创建并激活虚拟环境 (推荐)**
```bash
python3 -m venv venv
source venv/bin/activate # macOS/Linux
# 或 venv\Scripts\activate # Windows
```
3. **安装依赖**
```bash
pip install -r requirements.txt
```
## 使用方法
### 1. 抓取今天发布的数据 (默认)
直接运行脚本,程序将自动抓取发布日期为今天的“中标结果”公告。
```bash
python ygp_crawler.py
```
### 2. 抓取指定日期范围
使用 `--start-date``--end-date` 参数(格式:`YYYY-MM-DD`)。
```bash
python ygp_crawler.py --start-date 2026-02-01 --end-date 2026-02-04
```
### 3. 自定义输出文件路径
使用 `-o``--output` 参数指定输出 CSV 文件的路径(默认为 `results.csv`)。
```bash
python ygp_crawler.py --start-date 2026-02-01 --end-date 2026-02-04 -o my_data.csv
```
### 4. 增量爬取
使用 `-i``--incremental` 参数启用增量爬取模式。脚本会自动读取已有 CSV 文件,计算时间范围,只抓取新数据。
**自动计算日期范围(推荐)**
```bash
# 自动从已有数据的最新日期+1开始爬取到今天
python ygp_crawler.py -i
```
**手动指定日期范围**
```bash
# 在增量模式下手动指定日期范围
python ygp_crawler.py -i --start-date 2026-02-01 --end-date 2026-02-04
```
**增量爬取特性**
- 自动识别已有 CSV 文件中的数据时间范围
- 自动去重(根据详情链接判断)
- 新数据插入到文件前面,旧数据保留在后面
- 如果无新数据可抓取,自动退出
## 数据输出示例
### 终端输出JSON 格式,便于阅读)
```json
{
"项目标题": "某某项目中标结果公示",
"发布时间": "2026-02-04 17:30:02",
"详细链接": "https://ygp.gdzwfw.gov.cn/#/44/new/jygg/v3/A?noticeId=..."
}
```
### CSV 文件格式
```csv
项目标题,发布时间,详细链接
某某项目中标结果公示,2026-02-04 17:30:02,https://ygp.gdzwfw.gov.cn/#/44/new/jygg/v3/A?...
```