Skip to content

Commit 6a9eb63

Browse files
committed
run selenium as headless mode with argument
1 parent 98161fe commit 6a9eb63

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

util.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os, bs4
22
from selenium import webdriver
33

4-
APP_DIR = os.path.dirname(os.path.dirname("__filename__"))
4+
APP_DIR = os.path.dirname(os.path.dirname('__filename__'))
55

66

77
def get_text(element):
@@ -17,19 +17,19 @@ class Chrome:
1717
_chrome_options = webdriver.ChromeOptions()
1818
_driver = None
1919

20-
def __init__(self):
21-
# Uncomment if you DO NOT want GUI
22-
# self._chrome_options.add_argument('--headless')
23-
# self._chrome_options.add_argument('--no-sandbox')
24-
# self._chrome_options.add_argument('--disable-dev-shm-usage')
25-
# self._chrome_options.add_argument('--disable-gpu')
20+
def __init__(self, headless=False):
21+
if headless:
22+
self._chrome_options.add_argument('--headless')
23+
self._chrome_options.add_argument('--no-sandbox')
24+
self._chrome_options.add_argument('--disable-dev-shm-usage')
25+
self._chrome_options.add_argument('--disable-gpu')
2626
self._chrome_options.add_argument('--window-size=1920x1080')
2727
self._chrome_options.add_argument('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36')
2828
self._driver = self.create_driver()
2929

3030
def create_driver(self):
31-
driver = webdriver.Chrome(self._chrome_driver, chrome_options=self._chrome_options)
31+
driver = webdriver.Chrome(self._chrome_driver, options=self._chrome_options)
3232
return driver
3333

3434
def get_driver(self):
35-
return self._driver
35+
return self._driver

0 commit comments

Comments
 (0)