在这段代码中,我认为只有 --headless 可以正常工作
我尝试使用 -p 或 --profile “firefox 配置文件的路径”,但这些都不起作用
def initialize_web_driver():
try:
firefox_options = webdriver.FirefoxOptions()
firefox_options.add_argument('--headless')
firefox_options.add_argument("-p GPTT")
firefox_options.set_preference("browser.shell.checkDefaultBrowser", False)
driver = webdriver.Firefox(options=firefox_options)
driver.set_window_size(1920, 1080)
return driver
except Exception as e:
print(f"Error initializing WebDriver: {str(e)}")
return None
尝试
fp = webdriver.FirefoxProfile('/path/to/profile')
或
FirefoxProfile profile = new FirefoxProfile(new File("path/to/profile"));
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);