ygp-gdzwfw-gov-cn/README.md

74 lines
2.2 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 文件,同时输出到终端。
- **自定义输出路径**:支持通过参数指定输出文件路径。
## 环境要求
- 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
```
## 数据输出示例
### 终端输出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?...
```