Files
intl_news/scripts/domestic_crawl_2g.sh
T
2026-07-18 16:13:52 +08:00

51 lines
1.6 KiB
Bash
Executable File
Raw 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.
#!/bin/bash
# =============================================
# 国内服务器:2G headless stealth 抓取
# =============================================
# 适用场景:
# - 日常轻量补充抓取
# - RSS 优先 + headless stealth Web 回退
# - 可选 SOCKS5 代理(修改 profiles/2g_headless.yaml 中 proxy.enabled
#
# 用法:
# bash scripts/domestic_crawl_2g.sh # 抓取全部源
# bash scripts/domestic_crawl_2g.sh reuters # 只抓取指定源
# =============================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
cd "$PROJECT_DIR"
LOG() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"; }
LOG "══════ 国内 2G headless stealth 抓取 ══════"
LOG "Profile: 2g_headless"
LOG "内存上限: 1800 MB"
LOG "浏览器模式: stealth headless"
# ── 加载 .env ──
export $(grep -v '^#' .env | grep -v '^$' | xargs 2>/dev/null || true)
# ── 设置 Profile ──
export EN_NEWS_PROFILE="2g_headless"
# ── 执行抓取 ──
SOURCE_ARG=""
if [ $# -ge 1 ]; then
SOURCE_ARG="--source $1"
LOG "目标源: $1"
else
LOG "目标源: 全部启用源"
fi
PYTHONPATH=. .venv/bin/python3 -c "
from crawler.orchestrator import run_crawl_sync
import sys
source_filter = sys.argv[1] if len(sys.argv) > 1 else None
stats = run_crawl_sync(source_filter=source_filter)
print(f'抓取完成: {stats.sources_crawled} 源, {stats.total_articles} 篇')
" "$1"
LOG "══════ 2G 抓取完成 ✅ ══════"