-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
49 lines (43 loc) · 1.84 KB
/
__init__.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
import os, json
from selenium import webdriver
# Getting the path of the script file
dirname = os.path.dirname(__file__)
# Load configurations from config file
config = {}
with open(f"{dirname}/scrapper_config.json", 'r') as config_file:
config = json.load(config_file)
# Path to the web Driver file:
PATH = f"{dirname}/{config['driver'][config['browser']]}{['', '.exe'][config['Windows']]}"
# Defining a Function to initialize the drivers
def get_driver():
if config['browser'] == "Chrome":
# Configuring Chrome Driver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
if config['headless']:
# Headless Configuration
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
# Return chrome driver invocation
return webdriver.Chrome(executable_path=PATH, options=chrome_options)
elif config['browser'] == "Firefox":
# Cofiguring Firefox Driver
from selenium.webdriver.firefox.options import Options
firefox_options = Options()
if config['headless']:
# Headless Configuration
firefox_options.headless = True
# Return firefox driver invocation
return webdriver.Firefox(executable_path=PATH, options=firefox_options)
elif config['browser'] == "Edge":
# Configuring the Edge Driver
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
edge_options = EdgeOptions()
edge_options.use_chromium = True
if config['headless']:
# Headless Configuration
edge_options.add_argument('--headless')
edge_options.add_argument('--disable-gpu')
# Return firefox driver invocation
return Edge(executable_path=PATH, options=edge_options)