Python中Selenium WebDriver无法在Firefox中运行问题求助
Hey there, let's figure out why your Selenium + Firefox setup is throwing that error. The traceback you shared points to a failure starting the browser service, which almost always means GeckoDriver isn't properly configured—this is the bridge between Selenium and Firefox that's required for them to communicate, even with the latest versions of both.
Here's how to fix it step by step:
1. Download the right GeckoDriver
Grab the latest GeckoDriver version that matches your system architecture (since your Python is 32-bit, you can grab the 32-bit build, though 64-bit usually works too). The latest GeckoDriver is fully compatible with the latest Firefox, so you don't have to worry about version mismatches here.
2. Configure GeckoDriver (pick one method)
Method 1: Add to Python's Scripts folder
Copy the geckodriver.exe file into your Python installation's Scripts directory—for your setup, that path is:C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\Scripts
This way, your system will automatically find the driver when Selenium needs it.
Method 2: Specify path directly in code (Selenium 4+ recommended)
Use the Service class to tell Selenium exactly where your GeckoDriver is located. Update your code like this:
from selenium import webdriver from selenium.webdriver.firefox.service import Service # Replace this path with where you saved geckodriver.exe gecko_driver_path = r'C:\your\actual\path\to\geckodriver.exe' service = Service(gecko_driver_path) browser = webdriver.Firefox(service=service)
Method 3: Add to system PATH
Add the folder containing geckodriver.exe to your system's PATH environment variable. After doing this, restart your command prompt or IDE, then run your original code again—it should find the driver automatically.
Why this happens
Selenium doesn't come bundled with browser drivers. For Firefox, it relies on GeckoDriver to send commands to the browser. If the driver isn't in a location your system can find (either via PATH or explicit path in code), Selenium can't start the Firefox service, leading to the error you saw.
内容的提问来源于stack exchange,提问作者MAS

