# pc_price_tracker **Repository Path**: epsos/pc_price_tracker ## Basic Information - **Project Name**: pc_price_tracker - **Description**: 追踪指定商品在HisPrice和京东平台的价格变化,并记录爬取时间和价格信息 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-09 - **Last Updated**: 2026-02-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 商品价格追踪爬虫 ## 项目概述 这是一个Python爬虫程序,用于追踪指定商品在HisPrice和京东平台的价格变化,并记录爬取时间和价格信息。 ## 支持的商品 - gtx1650 - gtx3060 - gtx4060 - ryzen 5600g - ryzen 5600gt - i5-14600K ## 数据源 - [HisPrice](https://www.hisprice.com) - [京东](https://www.jd.com) ## 项目结构 ``` pc_price_tracker/ ├── config/ # 配置文件目录 │ └── config.json # 主配置文件 ├── data/ # 数据存储目录 ├── src/ # 源代码目录 │ ├── spiders/ # 爬虫模块 │ │ ├── hisprice_spider.py # HisPrice爬虫 │ │ └── jd_spider.py # 京东爬虫 │ ├── config_loader.py # 配置加载模块 │ ├── data_store.py # 数据存储模块 │ └── main.py # 主程序 ├── run.py # 运行脚本 ├── venv/ # Python虚拟环境 └── README.md # 项目说明 ``` ## 环境要求 - Python 3.7+ - Windows/Linux/MacOS ## 安装步骤 1. **克隆项目**(如果适用) 2. **初始化虚拟环境** ```bash python -m venv venv ``` 3. **激活虚拟环境** - Windows: ```bash .\venv\Scripts\Activate.ps1 ``` - Linux/Mac: ```bash source venv/bin/activate ``` 4. **安装依赖包** ```bash pip install requests beautifulsoup4 pandas lxml selenium webdriver-manager ``` ## 使用方法 ### 基本使用 运行完整的价格追踪: ```bash python run.py ``` ### 命令行参数 - `--products`:指定要追踪的商品列表 ```bash python run.py --products gtx1650 gtx3060 ``` - `--platforms`:指定要抓取的平台(hisprice或jd) ```bash python run.py --platforms hisprice ``` - `--output`:指定输出文件名 ```bash python run.py --output custom_output.csv ``` - `--by-product`:按商品分类保存数据 ```bash python run.py --by-product ``` ## 数据存储 - 数据默认保存在 `data/` 目录下 - 每日生成一个综合CSV文件,格式为 `price_tracking_YYYY-MM-DD.csv` - 如果使用 `--by-product` 参数,会为每个商品生成单独的CSV文件 ## 数据格式 CSV文件包含以下字段: - `product`:商品名称 - `name`:具体商品标题 - `price`:价格 - `url`:商品链接 - `platform`:平台名称 - `timestamp`:爬取时间 ## 注意事项 1. **反爬虫措施**:程序已内置请求间隔和错误重试机制,避免被网站封禁 2. **京东爬虫**:使用Selenium处理动态内容,首次运行会自动下载ChromeDriver 3. **网络环境**:确保网络连接正常,特别是访问京东时可能需要登录 4. **权限**:确保程序有写入 `data/` 目录的权限 ## 扩展功能 ### 添加新商品 编辑 `config/config.json` 文件,在 `products` 列表中添加新商品名称。 ### 添加新平台 1. 在 `src/spiders/` 目录下创建新的爬虫模块 2. 在 `config/config.json` 文件的 `websites` 部分添加平台信息 3. 在 `src/main.py` 中集成新爬虫 ## 故障排除 - **ChromeDriver错误**:确保Chrome浏览器已安装,或修改 `jd_spider.py` 使用其他浏览器 - **网络错误**:检查网络连接,或增加 `config.json` 中的 `timeout` 值 - **数据为空**:可能是网站结构变更,需要更新爬虫的选择器 ## 定期执行 可以通过以下方式设置定期执行: ### Windows 1. 打开「任务计划程序」 2. 创建新任务 3. 设置触发器(如每天特定时间) 4. 设置操作:启动程序 `python`,参数为 `run.py` 的完整路径 ### Linux/Mac 使用 `crontab` 设置定时任务: ```bash # 每天10点执行 0 10 * * * cd /path/to/pc_price_tracker && python run.py ``` ## 许可证 本项目仅供学习和个人使用,请勿用于商业用途。