1. 有界面运行
driver=webdriver.Chrome()
2.headless(无界面)
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
options.add_argument('--disable-dev-shm-usage')
driver=webdriver.Chrome(chrome_options=chrome_options)
3. 用函数实现多浏览器选择
def select_browser(weboption):
options = weboption
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
options.add_argument('--disable-dev-shm-usage')
return options
if driver == 'firefox':
options = select_browser(webdriver.FirefoxOptions())
driver = webdriver.Firefox(firefox_options=options)
else:
options=select_browser(webdriver.ChromeOptions())
driver=webdriver.Chrome(chrome_options=options)