一个功能完整的智能手表数据爬取、分析和对比系统,支持从ZOL网站爬取产品信息、京东价格查询和小红书用户评价收集。
smartwatch_crawler/ ├── main.py # 主程序入口 ├── config.py # 配置文件 ├── requirements.txt # 依赖包列表 ├── crawlers/ # 爬虫模块 │ ├── __init__.py │ ├── zol_crawler.py # ZOL网站爬虫 │ ├── jd_crawler.py # 京东价格爬虫 │ └── xhs_crawler.py # 小红书评价爬虫 ├── models/ # 数据模型 │ ├── __init__.py │ └── smartwatch.py # 智能手表数据模型 ├── database/ # 数据库模块 │ ├── __init__.py │ ├── db_manager.py # 数据库管理器 │ └── data_exporter.py # 数据导出器 ├── utils/ # 工具模块 │ ├── __init__.py │ ├── logger.py # 日志工具 │ └── http_client.py # HTTP客户端 ├── exports/ # 导出文件目录 ├── logs/ # 日志文件目录 └── tests/ # 测试文件
pip install -r requirements.txt
# 爬取1页产品
python main.py crawl-zol
# 爬取多页产品
python main.py crawl-zol --pages 3
# 为所有产品查询京东价格(每个产品最多3个商品)
python main.py crawl-jd
# 自定义每个产品的查询数量
python main.py crawl-jd --limit 5
# 为所有产品爬取小红书评价(每个产品最多10条)
python main.py crawl-xhs
# 自定义每个产品的评价数量
python main.py crawl-xhs --limit 20
# 一键执行所有爬取任务
python main.py crawl-all
# 导出为Excel格式(默认)
python main.py export
# 导出为CSV格式
python main.py export --format csv
# 导出为JSON格式
python main.py export --format json
# 导出对比报告
python main.py export --format comparison
# 指定输出文件名
python main.py export --format excel --filename my_data.xlsx
编辑 config.py 文件来修改爬虫配置:
# 请求间隔(秒)
REQUEST_DELAY = 1
# 最大重试次数
MAX_RETRIES = 3
# 请求超时时间
TIMEOUT = 30
from database.db_manager import DatabaseManager
# 创建数据库管理器
db = DatabaseManager()
# 获取所有产品
products = db.get_all_products()
# 根据URL查找产品
product = db.get_product_by_url("https://detail.zol.com.cn/GPSwatch/index2107338.shtml")
from crawlers.zol_crawler import ZOLCrawler
# 创建ZOL爬虫
crawler = ZOLCrawler()
# 获取产品列表
products = crawler.get_product_list(page=1)
# 获取产品详情
product = crawler.get_product_details(product_url)
# 获取产品参数
parameters = crawler.get_product_parameters(param_url)
网络连接错误
解析错误
数据库错误
日志文件保存在 logs/ 目录下,按日期和模块分类:
main_YYYYMMDD.log: 主程序日志zol_crawler_YYYYMMDD.log: ZOL爬虫日志jd_crawler_YYYYMMDD.log: 京东爬虫日志xhs_crawler_YYYYMMDD.log: 小红书爬虫日志欢迎提交Issue和Pull Request来改进这个项目!
MIT License