aboutsummaryrefslogtreecommitdiff
path: root/web_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'web_utils.py')
-rw-r--r--web_utils.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/web_utils.py b/web_utils.py
index 89c6632..1962489 100644
--- a/web_utils.py
+++ b/web_utils.py
@@ -1,7 +1,7 @@
import httpx2
import subprocess
import re
-from typing import Dict, Union
+from typing import Dict, Optional, Union
from dataclasses import dataclass
@@ -44,14 +44,18 @@ def html_to_markdown(html: str) -> str:
raise RuntimeError(f"Unexpected error during markdown conversion: {e}")
-def fetch_and_markdownify(url: str) -> FetchResult:
- """Fetches a web page and transforms it to markdown, with memoization."""
+def fetch_and_markdownify(url: str, proxy: Optional[str] = None) -> FetchResult:
+ """Fetches a web page and transforms it to markdown, with memoization.
+
+ If `proxy` is given (e.g. 'socks5://host:1080'), the request is routed
+ through that SOCKS5 proxy.
+ """
if url in _cache:
return _cache[url]
try:
with httpx2.Client(
- headers={"User-Agent": "Mozilla/5.0"}, timeout=10.0
+ headers={"User-Agent": "Mozilla/5.0"}, timeout=10.0, proxy=proxy
) as client:
response = client.get(url)
response.raise_for_status()