Schedule Python Selenium to run daily using Batch .bat

萝らか妹 提交于 2019-12-25 01:22:25

问题


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

my .bat script:

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

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

回答1:


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.

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



来源:https://stackoverflow.com/questions/57930453/schedule-python-selenium-to-run-daily-using-batch-bat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!