【问题标题】:How do you start a Selenium in Firefox or Chrome? [closed]如何在 Firefox 或 Chrome 中启动 Selenium? [关闭]
【发布时间】:2026-02-04 19:55:02
【问题描述】:

如何在 Google 或 Chrome 中设置 Selenium?

我都试过了,都没有成功。

它将在树莓派模型 b v1.1 上

【问题讨论】:

    标签: python selenium firefox raspberry-pi selenium-chromedriver


    【解决方案1】:

    首先您需要安装 ChromeDriver,您可以从 here 获得它。之后,您需要使用pip install selenium 安装 selenium 库。开始吧

    from selenium import webdriver
    driver = webdriver.Chrome('/path/to/chromedriver') # Optional arg (will search current directory if not supplied)
    driver.get('http://www.google.com/');
    

    【讨论】:

    • 是的,已经做到了:我的代码中有一个 while true 循环,它运行代码,等待一段时间,然后再次循环。在第二轮我总是得到这个错误:Exception has occurred: MaxRetryError HTTPConnectionPool(host='127.0.0.1', port=65216): Max retries exceeded with url: /session/2f594c29cf83c6b4d367bb43277ac0f6/url (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000002B665C049D0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
    • 您能否在浏览器中手动访问该链接?可能是服务器没有运行
    【解决方案2】:

    你好,这是一个很容易在 youtube 上搜索的问题,有很多视频可以正确解释这一点(例如如何创建 chrome PATH)

    我认为这个视频是一个很好的起点 https://www.youtube.com/watch?v=Xjv1sY630Uc

    谢谢。

    【讨论】:

      【解决方案3】:

      将chromedriver和python脚本放在同一目录

      然后写:

      from selenium import webdriver
      
      browser = webdriver.Chrome()
      driver.get('http://www.google.com/')
      

      【讨论】: