from selenium.webdriver.chrome.options import Options from selenium import webdriver # 无界面 def nobrowser(): chrome_options = Options() chrome_options.add_argument(‘--headless‘) chrome_options.add_argument(‘--disable-gpu‘) driverChrome = webdriver.Chrome(executable_path="chromedriver.exe",options=chrome_options) #path指定使用具体的chromedriver.exe return driverChrome
调用:
wd=nobrowser()
url="https://www.baidu.com"
wd.get(url)
# 有界面 def browser(): driverChrome = webdriver.Chrome(executable_path="“chromedriver.exe") return driverChrome
调用:
wd=nobrowser()
url="https://www.baidu.com"
wd.get(url)
无界面firefox
from selenium.webdriver.firefox.options import Options
ff_option = Options()
ff_option.add_argument(‘-headless‘)
原文:https://www.cnblogs.com/xkdn/p/12329954.html