Files
2026-04-15 18:12:30 +08:00

66 lines
4.6 KiB
Markdown
Raw Permalink 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.
# 详情采集
## 概述
负责按店铺和分类分页请求商品详情列表,并把原始分页响应写入 `category_detail_log`。
## 技术栈
Python、`requests`、`pymysql`、线程池、代理池、外部签名服务。
## 文件清单
### 小象超市详情列表请求部分.py
当前主用的详情分页采集脚本。
| 标签 | 函数/变量 | 作用 | 输入 | 输出 |
|------|-----------|------|------|------|
| [核心] | `get_sign_new(url, data, dfpid, mtg_origin)` | 调用外部签名服务生成新的 `mtgsig` | `(str, str, str, dict)` | `str` |
| [核心] | `update_headers(is_ok, hd_id)` | 更新 `elephant_headers` 的状态或计数 | `(int, int)` | `None` |
| [辅助] | `get_Datatext(dataq)` | 把参数字典拼成查询字符串 | `(dict)` | `str` |
| [实验] | `return_id1(keyword1, keyword2)` | 从本地 `all` 样例里反查一级/二级分类 id | `(str, str)` | `tuple[int, int] | None` |
| [辅助] | `next_or(response)` | 判断响应是否还有下一页 | `(Response)` | `bool` |
| [核心] | `one_(id1, id2, num, shop_id, hd, prox, one_all_num=None)` | 发起单页详情请求 | `(int, int, int, int, tuple, dict, int | None)` | `(Response, int)` |
| [核心] | `all_one(shop_id, workid, hd, work_queue)` | 为分类先请求第一页并回填总量信息 | `(int, str, tuple, Queue)` | `int` |
| [核心] | `one_all(workid, hd, work_queue)` | 在已知总量前提下补齐分类剩余分页 | `(str, tuple, Queue)` | `int` |
| [核心] | `get_hds()` | 读取可用详情 headers | `()` | `list[tuple]` |
| [辅助] | `worker_allone(shop_id, workid, hd, work_queue)` | 驱动 `all_one()` 的线程工作函数 | `(int, str, tuple, Queue)` | `None` |
| [辅助] | `worker(workid, hd, work_queue)` | 驱动 `one_all()` 的线程工作函数 | `(str, tuple, Queue)` | `None` |
| [核心] | `run_all_one(hds, workid, shop_id_list, one_ids)` | 批量完成各分类第一页采集 | `(list, str, list[int], list[int])` | `None` |
| [核心] | `run_one_all(hds, workid, shop_id_list)` | 批量补齐所有分类剩余页 | `(list, str, list[int])` | `None` |
| [辅助] | `get_prox()` | 从代理表加载城市代理并映射到店铺 | `()` | `dict` |
| [辅助] | `get_workid()` | 生成详情采集默认 `work_id` | `()` | `str` |
| [辅助] | `get_shop_id_list()` | 获取待跑店铺列表 | `()` | `list[int]` |
| [核心] | `main()` | 装载 headers、代理并启动详情采集主流程 | `()` | `None` |
### 小象超市详情补采部分.py
旧版补采脚本,通过已有 `data_completed` 数量反推缺页并补写日志。
| 标签 | 函数/变量 | 作用 | 输入 | 输出 |
|------|-----------|------|------|------|
| [废弃] | `get_sign_new(url, data, dfpid, mtg_origin)` | 旧版签名调用 | `(str, str, str, dict)` | `str` |
| [废弃] | `get_Datatext(dataq)` | 旧版参数拼接 | `(dict)` | `str` |
| [废弃] | `get_hd()` | 从旧表 `elephant_hd` 取单个 header | `()` | `list[tuple]` |
| [废弃] | `return_id1(keyword1, keyword2)` | 从 `all` 样例反查分类 id | `(str, str)` | `tuple[int, int] | None` |
| [废弃] | `next_or(response)` | 判断是否还有下一页 | `(Response)` | `bool` |
| [废弃] | `one_(keywordid1, keywordid2, num, shop_id, data)` | 基于已有商品 id 补请求单页 | `(int, int, int, int, list)` | `(Response, int)` |
| [废弃] | `all_one(shop_id, one_id, format_today)` | 旧版按一级分类补页 | `(int, int, str)` | `None` |
### elephant_one_all_checkpoint.json
详情翻页阶段的进度快照文件。
| 标签 | 函数/变量 | 作用 | 输入 | 输出 |
|------|-----------|------|------|------|
| [辅助] | `one_all checkpoint` | 保存最近一次成功翻页请求的分类、页码和偏移量快照 | `状态字典` | `恢复参考` |
## 依赖关系
- `小象超市详情列表请求部分.py` -> `newsetting.py`(数据库工具)
- `小象超市详情列表请求部分.py` -> `headers_project.elephant_headers`(读取详情 headers)
- `小象超市详情列表请求部分.py` -> `headers_project.proxs_list`(按城市加载代理)
- `小象超市详情列表请求部分.py` -> `tk_test.category_detail`(读取/更新任务进度)
- `小象超市详情列表请求部分.py` -> `tk_test.category_detail_log`(写原始分页响应)
- `小象超市详情列表请求部分.py` -> 外部签名服务(生成 `mtgsig`)
## 备注
- 当前 `main()` 只默认执行 `run_all_one()`,`run_one_all()` 需要手工切换启用。
- `return_id1()` 依赖根目录 `all` 样例文件,不属于主流程必需路径。
- 旧版 `小象超市详情补采部分.py` 已被 `小象超市缺漏页补采.py` 替代,不再作为主链路。