24 lines
674 B
Python
24 lines
674 B
Python
from selenium import webdriver
|
|
from selenium.webdriver.firefox.options import Options
|
|
from selenium.webdriver.firefox.service import Service
|
|
import psutil
|
|
|
|
def get_webdriver():
|
|
options = Options()
|
|
options.add_argument('--headless') # Optional
|
|
options.binary_location = '/opt/firefox/firefox'
|
|
|
|
service = Service('/usr/local/bin/geckodriver')
|
|
|
|
driver = webdriver.Firefox(options=options, service=service)
|
|
return driver, service
|
|
|
|
def kill_process_tree(pid):
|
|
try:
|
|
parent = psutil.Process(pid)
|
|
for child in parent.children(recursive=True):
|
|
child.kill()
|
|
parent.kill()
|
|
except psutil.NoSuchProcess:
|
|
pass
|