爬虫脚手架框架 - 快速创建和运行爬虫任务
Project description
spiderWei_TecDo 爬虫框架
快速创建和运行爬虫任务的脚手架框架。
安装
# 开发模式安装(推荐)
cd spiderWei
pip install -e .
# 或直接安装
pip install .
快速开始
1. 创建爬虫
# 在当前目录创建爬虫
spiderWei_TecDo start my_spider
# 在指定目录创建
spiderWei_TecDo start my_spider -o ./spiders
2. 查看配置说明
spiderWei_TecDo list
3. 编辑生成的爬虫文件
打开生成的 my_spider.py,修改以下内容:
-
Apollo 配置 - 根据实际环境修改
APOLLOID='Your-Apollo-ID', APOLLO_URL_TEST='http://your-test-apollo.com', APOLLO_URL_PROD='http://your-prod-apollo.com',
-
数据推送配置 - 二选一
DB_table_name='your_table_name', # 直接写表 # 或 DB_topic_name='your_topic_name', # 写 Kafka
-
实现
getexeList()函数 - 构造任务列表def getexeList(): return [{"id": 1}, {"id": 2}, {"id": 3}]
-
实现
main(arg, app)函数 - 编写采集逻辑def main(arg, app): # 发起请求 result = app.crawl.crawl(f"https://api.example.com/{arg['id']}") data = json.loads(result['html']) # 推送数据 app.push_queue.put({"id": arg['id'], "data": data})
4. 运行爬虫
python my_spider.py
配置项说明
| 配置项 | 说明 | 默认值 |
|---|---|---|
| Apollo配置 | ||
| APOLLOID | Apollo 应用ID | 'Creatives-spider' |
| APOLLO_URL_TEST | 测试环境 Apollo 地址 | 'http://dev-apollo.tec-develop.com' |
| APOLLO_URL_PROD | 生产环境 Apollo 地址 | 'http://hwsgprod.in.apolloconfig...:8080' |
| 环境配置 | ||
| isTest | 从环境变量 ISTEST 获取 | 默认 1 (测试环境) |
| Threadnum | 并发线程数 | 20 |
| 代理配置 | ||
| openproXies | 是否启用代理 | 1 (启用) |
| 数据库配置 | ||
| readDb | 是否连接数据库 | 1 (连接) |
| DB_table_name | 数仓表名 | '' |
| DB_topic_name | Kafka Topic | '' |
| PRIMARY_KEY_NAME | 主键名 | '' |
| Kafka配置 | ||
| needKafka | 是否需要Kafka | 1 (需要) |
| download_topic_name | 下载器Topic | '' |
| OBS/OSS配置 | ||
| needOBS | 是否需要对象存储 | 0 (不需要) |
| isHwOBS | OBS类型 | 0 (阿里云) |
| 调试配置 | ||
| is_print_item | 是否打印推送数据 | 0 (不打印) |
环境变量
# Windows
set ISTEST=0 # 0=生产环境, 1=测试环境
# Linux/Mac
export ISTEST=0
app 对象属性
在 main(arg, app) 函数中,app 对象提供以下属性:
app.push_queue- 数据推送队列app.download_queue- 下载器队列app.holo_client- 数据库客户端app.OBSHelper- OBS/OSS 客户端app.videoOp- 视频操作工具app.fileOp- 文件操作工具app.crawl- 爬虫请求工具app.configurations- Apollo 配置
依赖
- requests
- psycopg
- kafka-python
- yt-dlp
- esdk-obs-python
- oss2
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
spiderwei_tecdo-1.0.0.tar.gz
(16.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spiderwei_tecdo-1.0.0.tar.gz.
File metadata
- Download URL: spiderwei_tecdo-1.0.0.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
576d0fe24b237bb210f011f4c30da4167dcf27f4fb2e72e2acf8a90e58646ee4
|
|
| MD5 |
49545ac16ad1983b4f3fda061e237097
|
|
| BLAKE2b-256 |
94ff2659f402dafc187e87eddba339ee12683456d68b5b7f0934a0482ad2476e
|
File details
Details for the file spiderwei_tecdo-1.0.0-py3-none-any.whl.
File metadata
- Download URL: spiderwei_tecdo-1.0.0-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18d7b82e3a9242a81658dd4e306aa7721a89427f1672f72ac80c967a265bf92e
|
|
| MD5 |
d6dd0177be70f0cdf34b3e92a343ef2e
|
|
| BLAKE2b-256 |
54261f197743707d55482f3e5a7462d122bec000549d3f90f9f4075fede3f799
|