This repository has been archived on 2024-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
proxyapi/tools.py

25 lines
598 B
Python
Raw Permalink Normal View History

2024-01-18 11:17:32 +08:00
import os
import subprocess
import tempfile
def download_html_with_wget(url):
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
tmp_file_name = tmp_file.name
command = ['wget', '-q', '-O', tmp_file_name, url]
try:
subprocess.run(command, check=True)
with open(tmp_file_name, 'r') as file:
content = file.read()
return content
except subprocess.CalledProcessError as e:
print(f'An error occurred: {e}')
return None
finally:
if os.path.exists(tmp_file_name):
os.remove(tmp_file_name)