Running Chrome in Headless Mode with Selenium: Resolving the Persistent Executable Window
To perform web scraping without visible browser windows, Selenium users often employ ChromeDriver with the 'headless' option. However, some users report encountering a persistent executable window (.exe file) even after enabling headless mode.
To resolve this issue, we present a Python 2.7-compatible solution that effectively suppresses the executable window:
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"]) options.add_argument('headless') options.add_argument('window-size=0x0') chrome_driver_path = "C:\Python27\Scripts\chromedriver.exe" driver = webdriver.Chrome(executable_path=chrome_driver_path, options=options)
Additional Considerations:
Conclusion:
By implementing this modified code, you can effectively run Chrome in headless mode without the appearance of the browser window. This solution addresses the issue encountered by users experiencing the persistence of the executable file.
The above is the detailed content of Why Does Chrome Still Show an Executable Window Even in Headless Mode with Selenium?. For more information, please follow other related articles on the PHP Chinese website!