feat: 为出站请求统一接入 HTTP 代理
This commit is contained in:
@@ -16,6 +16,7 @@ from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from app.shared.config import Settings
|
||||
from app.shared.proxy import playwright_launch_proxy
|
||||
from app.scraping.core import site
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -100,7 +101,7 @@ class BrowserFallback:
|
||||
self._browser = await self._playwright.chromium.launch(
|
||||
headless=self._settings.browser_headless_effective,
|
||||
channel=self._settings.browser_channel or None,
|
||||
proxy=self._settings.playwright_proxy,
|
||||
proxy=playwright_launch_proxy(self._settings),
|
||||
timeout=self._settings.browser_launch_timeout_seconds * 1000,
|
||||
args=["--no-first-run", "--disable-blink-features=AutomationControlled"],
|
||||
)
|
||||
|
||||
@@ -22,6 +22,7 @@ from opentelemetry import trace
|
||||
|
||||
from app.scraping.core import rakuma_site as site
|
||||
from app.shared.config import Settings
|
||||
from app.shared.proxy import httpx_client_options
|
||||
from app.shared.errors import (
|
||||
ItemNotFoundError,
|
||||
ResourceBusyError,
|
||||
@@ -51,7 +52,7 @@ class RakumaSession:
|
||||
headers=site.default_headers(),
|
||||
timeout=self._settings.request_timeout_seconds,
|
||||
follow_redirects=True,
|
||||
proxy=self._settings.httpx_proxy,
|
||||
**httpx_client_options(self._settings),
|
||||
http2=True,
|
||||
)
|
||||
logger.info(
|
||||
|
||||
@@ -23,6 +23,7 @@ from opentelemetry import trace
|
||||
|
||||
from app.scraping.core import site
|
||||
from app.shared.config import Settings
|
||||
from app.shared.proxy import httpx_client_options
|
||||
from app.shared.errors import (
|
||||
ItemNotFoundError,
|
||||
ResourceBusyError,
|
||||
@@ -91,7 +92,7 @@ class SiteSession:
|
||||
headers=site.default_headers(mobile=mobile),
|
||||
timeout=self._settings.request_timeout_seconds,
|
||||
follow_redirects=True,
|
||||
proxy=self._settings.httpx_proxy,
|
||||
**httpx_client_options(self._settings),
|
||||
http2=True,
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user