更新 Cigarette/jinye_scraper.py
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
卷烟平台数据采集脚本 v4(通用格式 + 强制禁用代理)
|
||||
卷烟平台数据采集脚本 v4(通用格式 + 彻底禁用代理)
|
||||
- 数字列格式设为 'General'(G/通用格式)
|
||||
- 强制忽略系统代理(HTTP_PROXY/HTTPS_PROXY)
|
||||
- 清除系统代理环境变量,杜绝 SOCKS 代理错误
|
||||
- 修复调货价(第20列)转数字
|
||||
- 从第一个空白行开始写入
|
||||
"""
|
||||
@@ -85,7 +85,12 @@ def parse_cookies(s: str) -> dict:
|
||||
return c
|
||||
|
||||
def make_client(cookies: dict) -> httpx.Client:
|
||||
# 强制禁用代理,避免走 SOCKS/HTTP 代理
|
||||
# ---- 清除代理环境变量,防止 httpx 自动走 SOCKS/HTTP 代理 ----
|
||||
os.environ.pop('HTTP_PROXY', None)
|
||||
os.environ.pop('HTTPS_PROXY', None)
|
||||
os.environ.pop('http_proxy', None)
|
||||
os.environ.pop('https_proxy', None)
|
||||
# 创建客户端,不传递 proxies 参数(兼容所有 httpx 版本)
|
||||
return httpx.Client(
|
||||
cookies=cookies,
|
||||
headers={
|
||||
@@ -93,8 +98,7 @@ def make_client(cookies: dict) -> httpx.Client:
|
||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"Referer": f"{BASE_URL}/ui/pages/list.html?funCode={FUNCODE}"
|
||||
},
|
||||
timeout=30,
|
||||
proxies=None # ← 关键修改:忽略系统代理
|
||||
timeout=30
|
||||
)
|
||||
|
||||
# ── API ───────────────────────────────────────────────
|
||||
@@ -154,7 +158,7 @@ def write_cell(ws, row: int, col: int, value):
|
||||
if s:
|
||||
try: cell.value = int(float(s))
|
||||
except ValueError: cell.value = s
|
||||
cell.number_format = '0' # 整数格式
|
||||
cell.number_format = '0'
|
||||
return
|
||||
|
||||
if col in DEC_COLS:
|
||||
|
||||
Reference in New Issue
Block a user