Functional Script, with multiple Link download via Link.txt File

This commit is contained in:
2022-05-29 16:46:00 +02:00
parent a279b42414
commit 127dcd2cd7
3 changed files with 31 additions and 14 deletions
-1
View File
@@ -122,7 +122,6 @@ venv.bak/
/Driver /Driver
# mypy # mypy
.mypy_cache/ .mypy_cache/
.dmypy.json .dmypy.json
View File
+31 -13
View File
@@ -1,3 +1,4 @@
from itertools import count
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.service import Service from selenium.webdriver.firefox.service import Service
@@ -5,6 +6,9 @@ from selenium.webdriver.common.action_chains import ActionChains
import time import time
import os import os
with open("Links.txt") as fp:
Lines = fp.readlines()
curDir = os.path.abspath(os.getcwd()) curDir = os.path.abspath(os.getcwd())
folderName = "Downloads" folderName = "Downloads"
DownPath = os.path.join(curDir,folderName) 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.download.dir", DownPath)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream") 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 # Path to Driver
s = Service("Driver\geckodriver.exe") s = Service("Driver\geckodriver.exe")
driver = webdriver.Firefox(firefox_profile=profile,service=s) 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") time.sleep(5)
LinkField.send_keys(Link)
LinkField.send_keys(Keys.ENTER)
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") driver.close()
Download.click()
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.")