指定浏览器特性
FirefoxOptions
是为Firefox浏览器定义功能的新方法,通常应优先使用DesiredCapabilities。
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
设置自定义配置文件
可以为Firefox创建自定义配置文件,如下所示。
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
options=Options()
firefox_profile = FirefoxProfile()
firefox_profile.set_preference("javascript.enabled", False)
options.profile = firefox_profile