Headless Chrome无法启动:调试卡在driver.get行求助
Hey there, let's break down why your headless Chrome is getting stuck on driver.get() and how to fix it. Given your setup (Windows 7, Python 3.6), there are a few key areas to check:
Chrome Version Compatibility with Windows 7
Chrome dropped official support for Windows 7 starting with version 109. If you've updated Chrome to the latest version, it's likely incompatible with your OS, which causes headless mode to fail silently.
Fix: Downgrade Chrome to version 108 (the last version supporting Win7) and make sure yourchromedrivermatches this exact version—chromedriver and Chrome versions must always align perfectly.Add Critical Headless Mode Flags
Windows 7's older system components often need extra flags to get headless Chrome running smoothly. Try adding these to your Chrome options:from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() # Use --headless for Chrome <112; for 112+, use --headless=new (but stick to 108 for Win7) chrome_options.add_argument("--headless") chrome_options.add_argument("--no-sandbox") # Bypasses OS security restrictions (critical for Win7) chrome_options.add_argument("--disable-gpu") # Fixes GPU-related hangs on older systems chrome_options.add_argument("--disable-dev-shm-usage") # Resolves resource limit issues chrome_options.add_argument("--window-size=1920,1080") # Ensures proper page rendering driver = webdriver.Chrome(options=chrome_options) driver.get("your-target-site")Match Selenium Version to Python 3.6
Python 3.6 is end-of-life, and newer Selenium 4.x versions have dropped support for it. Stick to Selenium 3.141.0, which is fully compatible with Python 3.6 and older Chrome versions:pip install selenium==3.141.0Check Permissions and Chromedriver Path
- Run your Python script as an administrator (right-click > "Run as administrator")—Win7 sometimes blocks headless processes without elevated rights.
- Double-check that
chromedriver.exeis in your system PATH or explicitly specify its path in thewebdriver.Chrome()call:driver = webdriver.Chrome(executable_path="C:/path/to/chromedriver.exe", options=chrome_options)
内容的提问来源于stack exchange,提问作者Jan Šuman

