Files
intl_news/scripts/domestic_crawl_8g.sh
T
simonandClaude 5c106120bf feat: 增强反爬策略 + forexlive 迁移 investinglive
- crawler.py: 启用 magic/stealth 全自动反检测, --disable-webrtc,
  delay_before_return_html=3s, remove_consent_popups, 过滤列表页URL
- rss_crawler.py: 新增 _make_rss_client() 支持 httpx 代理,
  Google News RSS 跳过 article_url_pattern 域名过滤
- sources.yaml: investing.com 改用 Google News RSS 代理绕过Cloudflare;
  forexlive -> investinglive (域名已301重定向)
- domestic_crawl_8g.sh: HTTP_PROXY/HTTPS_PROXY 在 .env 加载前设置

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-23 09:25:23 +08:00

71 lines
2.2 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
# =============================================
# 国内服务器:8G headful + HTTP 代理抓取
# =============================================
# 适用场景:
# - 所有新闻源直接使用 headful Playwright 浏览器抓取
# - HTTP 代理 (127.0.0.1:3128) → Privoxy → SOCKS5(ss-local) 访问海外
# - 比海外 RSS 方式抓取更可靠,解决反爬问题
#
# 前置条件:
# sudo apt install xvfb
# Xvfb :99 -screen 0 1280x1024x24 & # 首次启动
# HTTP 代理 127.0.0.1:3128 已运行(privoxy
#
# 用法:
# bash scripts/domestic_crawl_8g.sh # 抓取全部源
# bash scripts/domestic_crawl_8g.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 "══════ 国内 8G headful + HTTP 代理抓取 ══════"
LOG "Profile: 8g_headful"
LOG "内存上限: 7500 MB"
LOG "浏览器模式: headful (Xvfb :99)"
LOG "HTTP 代理: 127.0.0.1:3128 (Privoxy → SOCKS5)"
# ── 加载 .env ──
export HTTP_PROXY=http://127.0.0.1:3128
export HTTPS_PROXY=http://127.0.0.1:3128
export $(grep -v '^#' .env | grep -v '^$' | xargs 2>/dev/null || true)
# ── 启动 Xvfb(如果尚未运行)──
if ! pgrep -x "Xvfb" > /dev/null; then
LOG "启动 Xvfb 虚拟显示器 :99 ..."
Xvfb :99 -screen 0 1280x1024x24 -ac +extension RANDR &
sleep 1
LOG "Xvfb 已启动 (PID: $(pgrep -x Xvfb))"
else
LOG "Xvfb 已在运行 (PID: $(pgrep -x Xvfb))"
fi
export DISPLAY=:99
# ── 设置 Profile ──
export EN_NEWS_PROFILE="8g_headful"
# ── 执行抓取 ──
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 "══════ 8G 抓取完成 ✅ ══════"