From 127dcd2cd7ad8e3c764997272d4c524c8b356d5f Mon Sep 17 00:00:00 2001 From: Py-Software Date: Sun, 29 May 2022 16:46:00 +0200 Subject: [PATCH] Functional Script, with multiple Link download via Link.txt File --- .gitignore | 1 - Links.txt | 0 main.py | 44 +++++++++++++++++++++++++++++++------------- 3 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 Links.txt diff --git a/.gitignore b/.gitignore index 82747b8..84aad92 100644 --- a/.gitignore +++ b/.gitignore @@ -122,7 +122,6 @@ venv.bak/ /Driver - # mypy .mypy_cache/ .dmypy.json diff --git a/Links.txt b/Links.txt new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py index cf92346..c285042 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +from itertools import count from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.firefox.service import Service @@ -5,6 +6,9 @@ from selenium.webdriver.common.action_chains import ActionChains import time import os +with open("Links.txt") as fp: + Lines = fp.readlines() + curDir = os.path.abspath(os.getcwd()) folderName = "Downloads" DownPath = os.path.join(curDir,folderName) @@ -15,24 +19,38 @@ profile.set_preference("browser.download.manager.showWhenStarting", False) profile.set_preference("browser.download.dir", DownPath) profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream") +def Download(): + for line in Lines: + Link = line.strip() + print("{}".format(line.strip())) -# Path to Driver -s = Service("Driver\geckodriver.exe") -driver = webdriver.Firefox(firefox_profile=profile,service=s) + # Path to Driver + s = Service("Driver\geckodriver.exe") + driver = webdriver.Firefox(firefox_profile=profile,service=s) -Link = "https://www.projekt-gutenberg.org/hugo/notreda1/notreda1.html" -DownloadURL = "http://www.epub2go.eu" + DownloadURL = "http://www.epub2go.eu" + driver.get(DownloadURL) -driver.get(DownloadURL) + LinkField = driver.find_element_by_id("spiegelURL") + LinkField.send_keys(Link) + LinkField.send_keys(Keys.ENTER) -LinkField = driver.find_element_by_id("spiegelURL") -LinkField.send_keys(Link) -LinkField.send_keys(Keys.ENTER) + time.sleep(5) -time.sleep(1) + Download = driver.find_element_by_xpath("/html/body/div/div[2]/div[1]/div/a") + Download.click() -Download = driver.find_element_by_xpath("/html/body/div/div[2]/div[1]/div/a") -Download.click() + driver.close() -driver.close() +if __name__ == "__main__": + start = time.time() + Download() + end = time.time() + + Dur = str(end - start) + print("") + print("") + print("") + print("Successfully download") + print(f"Duration: {Dur} seconds.") \ No newline at end of file