From 3370d01a5468854bcb095bfd6d3a974a1d2cef96 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn <github@nathan.woodburn.au> Date: Fri, 28 Feb 2025 21:55:15 +1100 Subject: [PATCH] fix: Update some script replacement and use custom requests-doh --- requirements.txt | 3 ++- tools.py | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4e7f470..65d4b04 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ dnspython cryptography datetime beautifulsoup4 -requests-doh \ No newline at end of file +requests-doh +git+https://github.com/Nathanwoodburn/requests-doh.git \ No newline at end of file diff --git a/tools.py b/tools.py index ad0eb5a..130fedf 100644 --- a/tools.py +++ b/tools.py @@ -18,7 +18,7 @@ import socket resolver = dns.resolver.Resolver() resolver.nameservers = ["194.50.5.28","194.50.5.27","194.50.5.26"] resolver.port = 53 -requests_doh.add_dns_provider("HNSDoH", "https://hnsdoh.com/dns-query") +DoHsession = requests_doh.DNSOverHTTPSSession("hnsdoh") # Disable warnings urllib3.disable_warnings() @@ -211,8 +211,7 @@ class ProxyError(Exception): def proxy(url: str) -> requests.Response: try: - session = requests_doh.DNSOverHTTPSSession("HNSDoH") - r = session.get(url,verify=False,timeout=30) + r = DoHsession.get(url,verify=False,timeout=30) return r except Exception as e: return ProxyError(str(e)) @@ -249,9 +248,10 @@ def cleanProxyContent(htmlContent: str,url:str, proxyHost: str): ignored = True break if not ignored: - # link.attrs[attrib] = f"{proxyUrl}/{link[attrib]}" - # Add path also - link.attrs[attrib] = f"{proxyUrl}/{urlparse(link[attrib]).path}/{link[attrib]}" + if link[attrib].startswith("/"): + link.attrs[attrib] = f"{proxyUrl}{link[attrib]}" + else: + link.attrs[attrib] = f"{proxyUrl}/{urlparse(url).path}{link[attrib]}" scripts = soup.find_all('script') for script in scripts: