-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_driver.py
More file actions
32 lines (22 loc) · 830 Bytes
/
get_driver.py
File metadata and controls
32 lines (22 loc) · 830 Bytes
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
#!/usr/bin/python
import shutil
from selenium import webdriver
import selenium.common.exceptions
def get_driver():
"""
Helps to grab webpages using headless Selenium.
:return: driver
"""
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
# Start the Chrome Driver
try:
driver = webdriver.Chrome(options=options) # sudo apt install chromium-chromedriver
except selenium.common.exceptions.NoSuchDriverException:
chromedriver_path = shutil.which("chromedriver")
service = webdriver.ChromeService(executable_path=chromedriver_path)
driver = webdriver.Chrome(options=options, service=service)
return driver
#driver.get('https://pacific.afn.mil/Gas-Prices/')
#page_source = driver.page_source