From 9ebf23c95c988ea0297be0ab9a281684122a38f1 Mon Sep 17 00:00:00 2001 From: dj346 Date: Fri, 24 Dec 2021 01:27:56 -0800 Subject: [PATCH] Created singlefile.py to download webpages. --- singlefile.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 singlefile.py diff --git a/singlefile.py b/singlefile.py new file mode 100644 index 0000000..de1a3cd --- /dev/null +++ b/singlefile.py @@ -0,0 +1,28 @@ +from subprocess import run + +SINGLEFILE_BINARY_PATH = ".\\node_modules\\single-file\\cli\\single-file" +#CHROME_PATH = "C:\\Program Files\\Google\Chrome\\Application\\chrome.exe" #Uncomment this and set your browser exe if it can't find yours. + +def addQuotes(str): + return "\"" + str.strip("\"") + "\"" + +def download_page(url, cookies_path, output_path, output_name_template = ""): + args = [ + addQuotes(SINGLEFILE_BINARY_PATH), + #"--browser-executeable-path=" + addQuotes(CHROME_PATH.strip("\"")), #Uncomment this and set your browser exe if it can't find yours. + "--browser-cookies-file=" + addQuotes(cookies_path), + "--output-directory=" + addQuotes(output_path), + url + ] + + if(output_name_template != ""): + args.append("--filename-template=" + addQuotes(output_name_template)) + + try: + run("node " + " ".join(args)) + except Exception as e: + print("Was not able to save the URL " + url + " using singlefile. The reported error was " + + e.strerror) + +#if __name__ == "__main__": + #download_page("https://www.google.com/", "", ".\\output\\test", "test.html") \ No newline at end of file