-
Notifications
You must be signed in to change notification settings - Fork 0
/
Master.py
56 lines (49 loc) · 2.21 KB
/
Master.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import webdriver
from selenium.webdriver.common.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from base64 import b64decode
from ast import literal_eval
from os.path import isfile, abspath
import zlib
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.chrome.webdriver import WebDriver
def createBrowser(url = '', headless=False, blockImages=True, hideConsole = False, downloadDirectory=None) -> WebDriver:
if not isfile('Master/chromedriver.exe'):
print("Missing chromedriver.exe file")
return None
chromeOptions = ChromeOptions()
prefs = {}
if blockImages:
prefs["profile.managed_default_content_settings.images"] = 2
if headless:
chromeOptions.add_argument("--headless")
chromeOptions.add_argument("--window-size=1920x1080")
if downloadDirectory:
prefs["download.default_directory"] = downloadDirectory+'\\'
prefs["directory_upgrade"] = True
if downloadDirectory or blockImages:
chromeOptions.add_experimental_option("prefs",prefs)
chrome_serv = webdriver.myService('path--to--exe.exe')
chrome_serv.service_args = ["hide_console", ]
if isfile('Master/chromedriver.exe'):
drive = abspath("Master/chromedriver.exe")
if hideConsole:
browser = webdriver.myWebDriver(executable_path=drive, chrome_options=chromeOptions, service_args=chrome_serv.service_args)
else:
browser = webdriver.myWebDriver(executable_path=drive, chrome_options=chromeOptions)
else:
if hideConsole:
browser = webdriver.myWebDriver(chrome_options=chromeOptions, service_args=chrome_serv.service_args)
else: browser = webdriver.myWebDriver(chrome_options=chromeOptions)
if url:
browser.get(url)
return browser
def Pkill(string='chromedriver.exe') -> None:
import psutil
for proc in psutil.process_iter():
# check whether the process name matches
if proc.name() == string:
proc.kill()