|
@ -2,14 +2,23 @@ import re |
|
|
import zipfile |
|
|
import zipfile |
|
|
import os, sys, stat, platform |
|
|
import os, sys, stat, platform |
|
|
from urllib.request import urlretrieve |
|
|
from urllib.request import urlretrieve |
|
|
|
|
|
from collections import namedtuple |
|
|
|
|
|
|
|
|
from clint.textui import puts, colored |
|
|
from clint.textui import puts, colored |
|
|
import progressbar |
|
|
import progressbar |
|
|
|
|
|
|
|
|
from selenium import webdriver |
|
|
from selenium import webdriver |
|
|
from selenium.webdriver.chrome.options import Options |
|
|
|
|
|
|
|
|
|
|
|
from .common import NO_CHROME_DRIVER |
|
|
from .common import NO_CHROME_DRIVER |
|
|
|
|
|
from ..exceptions import UnknownOSException |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ = namedtuple('WebDrivers', 'mac linux windows') |
|
|
|
|
|
drivers = ['https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_mac64.zip', |
|
|
|
|
|
'https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_linux64.zip', |
|
|
|
|
|
'https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_win32.zip' |
|
|
|
|
|
] |
|
|
|
|
|
WebDriver = _(drivers[0], drivers[1], drivers[2]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_zip(filename): |
|
|
def extract_zip(filename): |
|
@ -19,29 +28,28 @@ def extract_zip(filename): |
|
|
:return: new filename |
|
|
:return: new filename |
|
|
""" |
|
|
""" |
|
|
try: |
|
|
try: |
|
|
file = zipfile.ZipFile(filename, 'r') |
|
|
_file = zipfile.ZipFile(filename, 'r') |
|
|
except FileNotFoundError: |
|
|
except FileNotFoundError: |
|
|
puts(colored.red(f"{filename} Does not exist")) |
|
|
puts(colored.red(f"{filename} Does not exist")) |
|
|
sys.exit() |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
# Save the name of the new file |
|
|
# Save the name of the new file |
|
|
new_file_name = file.namelist()[0] |
|
|
new_file_name = _file.namelist()[0] |
|
|
|
|
|
|
|
|
# Extract the file and make it executable |
|
|
# Extract the file and make it executable |
|
|
file.extractall() |
|
|
_file.extractall() |
|
|
|
|
|
|
|
|
driver_stat = os.stat(new_file_name) |
|
|
driver_stat = os.stat(new_file_name) |
|
|
os.chmod(new_file_name, driver_stat.st_mode | stat.S_IEXEC) |
|
|
os.chmod(new_file_name, driver_stat.st_mode | stat.S_IEXEC) |
|
|
|
|
|
|
|
|
file.close() |
|
|
_file.close() |
|
|
os.remove(filename) |
|
|
os.remove(filename) |
|
|
return new_file_name |
|
|
return new_file_name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setup_selenium(driver_path, options): |
|
|
def setup_selenium(driver_path, options): |
|
|
# Configures selenium to use a custom path |
|
|
# Configures selenium to use a custom path |
|
|
driver = webdriver.Chrome(executable_path=driver_path, options=options) |
|
|
return webdriver.Chrome(executable_path=driver_path, options=options) |
|
|
return driver |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_webdriver(): |
|
|
def get_webdriver(): |
|
@ -59,23 +67,20 @@ def get_webdriver(): |
|
|
# Extract file |
|
|
# Extract file |
|
|
extract_zip(web_driver[0]) |
|
|
extract_zip(web_driver[0]) |
|
|
|
|
|
|
|
|
return os.getcwd() + '/chromedriver' |
|
|
return "{0}/chromedriver".format(os.getcwd()) |
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
|
# Download it according to the current machine |
|
|
# Download it according to the current machine |
|
|
webdrivers = ['https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_mac64.zip', |
|
|
|
|
|
'https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_linux64.zip', |
|
|
|
|
|
'https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_win32.zip' |
|
|
|
|
|
] |
|
|
|
|
|
os_platform = platform.system() |
|
|
os_platform = platform.system() |
|
|
if os_platform == 'Darwin': |
|
|
if os_platform == 'Darwin': |
|
|
chrome_webdriver = webdrivers[0] |
|
|
chrome_webdriver = WebDriver.mac |
|
|
elif os_platform == 'Linux': |
|
|
elif os_platform == 'Linux': |
|
|
chrome_webdriver = webdrivers[1] |
|
|
chrome_webdriver = WebDriver.linux |
|
|
elif os_platform == 'Windows': |
|
|
elif os_platform == 'Windows': |
|
|
chrome_webdriver = webdrivers[2] |
|
|
chrome_webdriver = WebDriver.windows |
|
|
else: |
|
|
else: |
|
|
raise Exception("Unknown Operating system platform") |
|
|
raise UnknownOSException("Unknown Operating system platform") |
|
|
|
|
|
|
|
|
global total_size |
|
|
global total_size |
|
|
|
|
|
|
|
@ -102,7 +107,8 @@ def get_webdriver(): |
|
|
if int(response[1].get('Content-Length')) == total_size: |
|
|
if int(response[1].get('Content-Length')) == total_size: |
|
|
puts(colored.green(f"DONE!")) |
|
|
puts(colored.green(f"DONE!")) |
|
|
|
|
|
|
|
|
return os.getcwd() + '/' + extract_zip(file_name) |
|
|
return "{0}/{1}".format(os.getcwd(), extract_zip(file_name)) |
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
|
puts(colored.red("An error Occurred While trying to download the driver.")) |
|
|
puts(colored.red("An error Occurred While trying to download the driver.")) |
|
|
# remove the downloaded file and exit |
|
|
# remove the downloaded file and exit |
|
|