简体   繁体   English

Python selenium 浏览器 firefox

[英]Python selenium browser firefox

Would like some help with why this isn't working想知道为什么这不起作用

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://www.google.com')

Error:错误:

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

Download geckodriver for Firefox from the below link,从以下链接下载 Firefox 的 geckodriver,

https://github.com/mozilla/geckodriver/releases

The geckodriver has to be in the code path or the path to it has to be specified. geckodriver 必须在代码路径中,或者必须指定它的路径。

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")

Final block of code:最后的代码块:

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.google.com")

More更多的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM