I am trying to open a webpage with selenium at a specific time, but it's not working. Here's my code:
import time
from selenium import webdriver
from datetime import datetime
while True:
PATH = "chromedriver.exe"
driver = webdriver.Chrome(PATH)
ct = datetime.now().strftime("%H:%M")
if ct == 8:55:
driver.get("https://webpage.com/")
else:
print("Waiting for time to be 8:55...")
time.sleep(100)
Expected: If the current time is 8:55, it has to open the webpage "https://webpage.com/", or else it should print the text "Waiting for the time to be 8:55" and sleep for 100 seconds.
Actual Result: The code is returning these errors:
Expected expression. Pylance [11, 19]
Type annotation not supported for this type of expression. Pylance [11, 19]
Unexpected indentation. Pylance [12, 9]
Unindent not expected. Pylance [15, 24]
Expected expression. Pylance [15, 24]
Statements must be separated by newlines or semicolons. Pylance [15, 24]
I am using Visual Studio Code as my IDE, and I have selenium installed.
CodePudding user response:
if ct == 8:55:
is a syntax error. You probably wanted to write
if ct == "08:55":
As a side note if you sleep for 100 seconds at, say, 08:54:50
it will be 08:56:30
when you wake up and you will miss your window. You should sleep less than 1 minute.