【问题标题】:Schedule Python Selenium to run daily using Batch .bat使用 Batch .bat 安排 Python Selenium 每天运行
【发布时间】:2019-09-14 07:11:05
【问题描述】:

我创建了一个批处理文件来运行 Python Selenium,但是浏览器没有打开,但是出现错误消息

    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

我的 .bat 脚本:

"C:\Users\tom\AppData\Local\Programs\Python\Python37-32\python.exe" "C:\Users\tom\Downloads\selenium.py"
pause

我在 Jupyter notebook 中的 python 代码是:

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys

time.sleep(3)
driver = webdriver.Chrome('chromedriver.exe')
time.sleep(1)
driver.maximize_window()
time.sleep(1)
driver.set_page_load_timeout('10')
driver.get('https://www.google.com/') 

【问题讨论】:

    标签: python-3.x selenium batch-file selenium-chromedriver


    【解决方案1】:

    ChromeDriver 在您的 PATH 中吗?我遇到了类似的错误,并且能够通过按照错误提示将其添加到我的路径来解决它。

    如果您不想将其添加到您的 PATH 中,您应该能够只指定确切的可执行位置。如果您用正确的路径替换路径,这应该对您有用。

    webdriver.Chrome(executable_path=r'C:\folder\path\to\chromedriver.exe')

    【讨论】:

    • 你就是男人,它有效。并确保使用直接的 python 3.7,不知道为什么 3.6 会引发其他问题。不要使用 Anaconda 的 pythonw.exe,它也会失败。 \anaconda3\pythonw.exe
    猜你喜欢
    • 2021-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 2022-06-12
    相关资源
    最近更新 更多