安排Python Selenium使用Batch .bat每天运行 [英] Schedule Python Selenium to run daily using Batch .bat

查看:171
本文介绍了安排Python Selenium使用Batch .bat每天运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I create a batch file to run Python Selenium, but the browser does not open, but with an error msg

    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笔记本中的python代码是:

my python code in Jupyter notebook is:

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/') 

推荐答案

ChromeDriver是否在您的PATH中?我遇到了类似的错误,并能够按照错误提示将其添加到我的路径中来解决.

Is ChromeDriver in your PATH? I have had a similar error and was able to resolve it by adding that to my path as the error suggests.

如果您不想将其添加到PATH中,则应该只需指定确切的可执行文件位置即可.如果您用正确的路径替换路径,这应该对您有用.

If you don't want to add it to your PATH you should be able to just specify the exact executable location. This should work for you if you replace the path with the correct one.

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

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

这篇关于安排Python Selenium使用Batch .bat每天运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆