Auto backup \2026-\04-\20

This commit is contained in:
Ubuntu
2026-07-08 16:00:02 +08:00
parent d285680356
commit 065fde366a
73 changed files with 174 additions and 57 deletions
+61 -1
View File
@@ -675,7 +675,67 @@ def download_image(url: str, temp_dir: str) -> tuple:
return filename, filepath, True
except Exception as e:
print(f"下载图片失败 {url}: {e}")
return None, None, False
# CDN 子域名回退(如 eewimg.cn 的 66 子域名在部分网络无法解析)
if 'eewimg.cn' in url and url.startswith('http'):
fallback_result = _try_eewimg_cdn_fallback(url, temp_dir)
if fallback_result and fallback_result[2]:
return fallback_result
return None, None, False
# eewimg.cn CDN 可解析的子域名(66 子域名在海外/部分网络 NXDOMAIN)
_EEWIMG_FALLBACK_SUBDOMAINS = ["8", "2", "10", "11", "12", "3", "1"]
def _try_eewimg_cdn_fallback(url: str, temp_dir: str) -> tuple:
"""尝试用其他 eewimg.cn 子域名下载图片"""
# 去掉 imageView2 等图片处理参数,获取原始图片
clean_url = re.sub(r'\?.*$', '', url)
for sub in _EEWIMG_FALLBACK_SUBDOMAINS:
try:
# 替换子域名(数字开头的子域名)
fallback_url = re.sub(r'https?://\d+\.eewimg\.cn', f'https://{sub}.eewimg.cn', clean_url)
if fallback_url == clean_url:
continue # 没替换成功,跳过
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Accept': 'image/avif,image/webp,image/apng,image/*,*/*;q=0.8',
'Referer': 'https://www.eeworld.com.cn/',
}
response = requests.get(fallback_url, headers=headers, timeout=15, stream=True)
response.raise_for_status()
content_type = response.headers.get('content-type', '')
ext = '.jpg'
if 'png' in content_type:
ext = '.png'
elif 'gif' in content_type:
ext = '.gif'
elif 'webp' in content_type:
ext = '.webp'
else:
parsed = urlparse(url)
path_ext = os.path.splitext(parsed.path)[1]
if path_ext:
ext = path_ext
filename = f"crawl_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:8]}{ext}"
filepath = os.path.join(temp_dir, filename)
with open(filepath, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print(f"[CDN fallback] 成功通过 {sub}.eewimg.cn 下载: {url}")
return filename, filepath, True
except Exception as e:
continue
return None, None, False
def is_spa_site(html: str) -> bool: