2

I am using a machine running windows 10 to automate a scraper that is written in python and uses selenium (with chrome driver). I want this to run every day at 3:00 am.

It seems the best way to do this is to write a batch file test_bat.bat that runs the python script in its virtual environment. Here are the contents of test_bat.bat:

C:\Users\data_miner\PycharmProjects\SeleniumScraper\venv\Scripts\activate.bat && python C:\Users\data_miner\PycharmProjects\SeleniumScraper\ScraperWindows.py

I learned how to do this here. This works excellently when run by clicking on the .bat file icon directly.

However, when fired (whether by the trigger or manually) there is no effect other than a change of status from 'ready' to 'running' and the pictured rows in history:

enter image description here

Details

The Action that I created has the following values (instructions were followed from here):

Action: Start a program, Program/script: C:\data_miner\Desktop\test_batch.bat

("C:\data_miner\Desktop\test_batch.bat" is the path to the batch file)

A similar problem that I have read the solution for:

HERE: the solution to this problem was setting the "working directory" to the location of the bat file. I first assumed that by working directory, they meant the 'Start in (optional)' field in 'Actions', this didn't work. Secondly I tried adding a cd command to the first line of the batch file: cd C:\data_miner\Desktop this also made no difference.

Comments

I can provide the python scripts if appropriate but chose not to here as the script works fine when run from the bat. The problem is in the transition from opening the bat to getting task scheduler to open it.

How do I get this thing to work?

4
  • 3
    There is absolutely no need to try to squeeze two commands onto one line in a batch file, so start by putting each onto a new line. Then, you need to Call the .bat file on the first line. Line 1: @Call "%UserProfile%\PycharmProjects\SeleniumScraper\venv\Scripts\activate.bat"; Line 2: @"%LocalAppData%\Programs\Python\Python39\python.exe" "C:\Users\data_miner\PycharmProjects\SeleniumScraper\ScraperWindows.py". Or Line 1: @CD /D "C:\Users\data_miner\PycharmProjects\SeleniumScraper" Line 2: "" Commented Aug 18, 2021 at 10:03
  • 1
    …, Or Line 1: @CD /D "%UserProfile%\PycharmProjects\SeleniumScraper"; Line 2: @Call "venv\Scripts\activate.bat"; Line 3: @"%LocalAppData%\Programs\Python\Python39\python.exe" "ScraperWindows.py". However, if you are running this under highest privileges, or as another user, then you should not use the %UserProfile% or %LocalAppData% variables: Line 1: @CD /D "%SystemDrive%\Users\data_miner\PycharmProjects\SeleniumScraper"; Line 2: @Call "venv\Scripts\activate.bat"; Line 3: @"%SystemDrive%\Users\data_miner\AppData\Local\Programs\Python\Python39\python.exe" "ScraperWindows.py" Commented Aug 18, 2021 at 10:17
  • @Compo Please consider posting your solution as an answer since it solved OP's problem (adding the path to the script). Commented Nov 10, 2023 at 20:12
  • @TylerH, the OP, who didn't tag me in their comment, did not specify which of the examples I suggested worked for them. Commented Nov 10, 2023 at 20:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.