【发布时间】:2018-05-07 03:36:47
【问题描述】:
我正在尝试创建一个在给定 URL 时刷新任何页面的功能。但是程序不会运行。我究竟做错了什么?这是我的代码:
from selenium import webdriver
import time
def page_refresh(url):
driver = webdriver.Firefox()
driver.get(url)
x = 0
while x <= 5:
time.localtime(10)
driver.refresh(url)
driver.close
page_refresh('https://www.wikipedia.org/')
这是我得到的:
Traceback (most recent call last):
File "C:\Users\100453649\PycharmProjects\AutoRefresher\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\100453649\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\100453649\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/100453649/PycharmProjects/AutoRefresher/Main.py", line 13, in <module>
page_refresh('https://www.wikipedia.org/')
File "C:/Users/100453649/PycharmProjects/AutoRefresher/Main.py", line 5, in page_refresh
driver = webdriver.Firefox()
File "C:\Users\100453649\PycharmProjects\AutoRefresher\venv\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 152, in __init__
self.service.start()
File "C:\Users\100453649\PycharmProjects\AutoRefresher\venv\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
【问题讨论】:
-
线索在异常的最后一行。未找到壁虎驱动程序。
-
堆栈跟踪中的最后一行定义了您的问题。 geckodriver 无法启动。它必须位于包含在
PATH变量中的目录中,或者您必须在启动webdriver 时将路径定义为webdriver 的参数。你安装了geckodriver吗?如果是这样,它在哪里?它是否位于PATH中定义的目录中?如果是这样,是否设置了权限,以便运行程序的用户可以启动它(可执行)?
标签: python selenium selenium-webdriver page-refresh