简体   繁体   中英

Run a scheduled task with ChromeDriver

I have made a script based on Selenium and Chromedriver. Basically a program that login into a site. Writes a comment (From a txt file from computer) and then closes the program and no it is not a spam script but a script I have made just to begin with python and selenium.

The program itself works very well if I start it manually. Then there is no issue and chromedriver is headless since I don't need to see the whole process chrome_options.add_argument("--headless")

Then I saw a post from here Scheduling a Python Script

and I did follow it设置

but the issue im having is that everytime it is the time and the program starts. It comes up the script and then a fast error which I managed to print

错误

Which I can see there is a issue with the Chromedriver. The thing is now. How can I make this script to work through schedule tasks with Chromedriver running on the background. I might have done the setup wrong but the program works manually so I guess there might be a issue with Windows schedule tasks?

Basically I just want the script to run on the background every xx:xx time.

Please feel free to comment if needed something more information.

    chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument('--disable-notifications')
chrome_options.add_argument("--headless")
chrome_options.add_argument("--user-agent=Mozilla/5.0 (Linux; Android 6.0; HTC One M9 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.implicitly_wait(5)

The driver you are using is too old and does not recognize ChromeHeadless, you need to use version 2.29 or newer:

Selenium ChromeDriver does not recognize newly compiled Headless Chromium (Python)

我遇到了同样的问题(使用较新的“无头”版本),解决方案是将 Windows 计划任务作为“管理员”(使用“s”)运行。

I had this problem and almost give up from task scheduler and started to write windows service which would run my web scraping application. If you got exception chrome unreachable or chrome didn't get response from HTTP server...

This make my application work even through task scheduler.

Task Scheduler -> Go on task -> Properties -> Conditions > Under Network -> Check Network Start only if the following network connection is available -> Select "Any connection".

Go this from this post windows-10-task-scheduler-not-running

When using selenium with Chrome, you have to make sure that your selenium version is compatible with the chrome version you have installed. If you get the app to work and then update your chrome you might get an unrecognized version error.

If you have chrome v 102.0 like me, you need to get the latest selenium chrome driver that is the same version as your browser.

See Example Below:

铬版

Chrome Driver Download: https://chromedriver.chromium.org/downloads Chrome 驱动下载

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM