想知道为什么它不起作用
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://www.google.com')
错误:
Traceback (most recent call last):
File "C:/Users/cycli/Desktop/test.py", line 2, in <module>
browser = webdriver.Firefox()
File "D:\Python\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "D:\Python\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "D:\Python\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 3221225595
答案 0 :(得分:1)
从下面的链接下载适用于Firefox的geckodriver,
https://github.com/mozilla/geckodriver/releases
壁虎驱动程序必须位于代码路径中,或者必须指定其路径。
from selenium.webdriver.firefox.options import Options
#Setting up FireFox Driver Options
driver_options = Options()
profile = webdriver.FirefoxProfile()
#driver_options.add_argument("--headless")
driver = webdriver.Firefox(
firefox_profile=profile,
options=driver_options,
executable_path="geckodriver.exe")
答案 1 :(得分:1)
最终代码块:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.google.com")