Python Selenium 打开浏览器但不加载页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40186299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:14:53  来源:igfitidea点击:

Selenium opens browser but doesn't load page

pythonseleniumfirefoxgeckodriver

提问by Senor Penguin

this is an extension from a previous post I made Herewhich I could not get to work but I am now getting a new error after updating Selenium.

这是我在这里发表的上一篇文章的扩展,我无法开始工作,但现在更新 Selenium 后出现新错误。

I am using Python 3.5, Windows 8.1, Selenium 3.0.1

我使用的是 Python 3.5、Windows 8.1、Selenium 3.0.1

I know the code works because it works on my MAC, but when I bring it over to my work computer which is described above, the only thing that happens is the browser will open but it wont load anything, not even a homepage.

我知道代码有效,因为它可以在我的 MAC 上运行,但是当我把它带到我上面描述的工作计算机上时,唯一发生的事情是浏览器会打开但它不会加载任何东西,甚至不会加载主页。

From everything I could find on search I downloaded the geckodriver, renamed it to wires.exe and I added the directory to the system PATH.

从我可以在搜索中找到的所有内容中,我下载了 geckodriver,将其重命名为wires.exe,并将目录添加到系统路径中。

sys

系统

I am completely lost on what to do to get this to work. Here is the code im using:

我完全不知道该怎么做才能让它发挥作用。这是我使用的代码:

from selenium import webdriver

driver = webdriver.Firefox()

driver.get('https://www.google.com')

Here are the errors I am getting:

以下是我收到的错误:

error

错误

回答by Andrew

I did not add geckodriver to PATH (it is located in the same directory as Python script), and after selenium update to 3.0.1 use this code to start selenium session:

我没有将 geckodriver 添加到 PATH(它与 Python 脚本位于同一目录中),并且在 selenium 更新到 3.0.1 后使用此代码启动 selenium 会话:

gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))
binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, executable_path=gecko+'.exe')

Additionally: you need update geckodriver to the latest version 0.11.1.

另外:您需要将 geckodriver 更新到最新版本 0.11.1。

回答by Ripon Al Wasim

You need to set geckodriver path as mentioned below:

您需要设置如下所述的 geckodriver 路径:

self.driver = webdriver.Firefox(executable_path = 'D:\Selenium_RiponAlWasim\geckodriver-v0.18.0-win64\geckodriver.exe')

Download geckodriverfor you suitable OS --> Extract it in a folder of your choice --> Set the path correctly.

下载geckodriver适合您的操作系统 --> 将其解压缩到您选择的文件夹中 --> 正确设置路径。

I'm using Python 3.6.2 and Selenium WebDriver 3.4.3

我正在使用 Python 3.6.2 和 Selenium WebDriver 3.4.3

回答by yasin lachini

For windows10 downloadgechodriver

对于windows10下载gechodriver

and extract it on like below . customize it for yourself. my username is yasin in windows10

并像下面那样提取它。为自己定制。我的用户名是 yasin 在 windows10

C:\Users\yasin\AppData\Local\Programs\Python\Python37\Scripts

回答by altabq

For Mac users: This problem (as well as the Notarization issueswith geckodriver) can be avoided by installing the software via homebrew.

对于 Mac 用户:通过homebrew安装软件可以避免这个问题(以及geckodriver的公证问题)。