刷新网页

2024-09-30 00:25:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使一个函数,刷新任何网页时,给定的网址。但程序无法运行。我做错什么了?这是我的密码:

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. 

Tags: inpyurllibdriverseleniumlinepage
1条回答
网友
1楼 · 发布于 2024-09-30 00:25:48

你的例外清楚地表明

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

解决方案:

添加gecko驱动程序路径:

示例:

 from selenium import webdriver
 driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
 driver.get(url)

相关问题 更多 >

    热门问题