带有 if-else 语句的 Selenium 不起作用

Selenium with if-else statements not working

我想在特定时间用 selenium 打开一个网页,但它不起作用。这是我的代码:

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)

预期:如果当前时间是8:55,它必须打开网页“https://webpage.com/”,否则它应该打印文本“Waiting for the time to成为 8:55" 并休眠 100 秒。

实际结果:代码返回这些错误:

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]

我正在使用 Visual Studio 代码作为我的 IDE,并且我安装了 selenium。

if ct == 8:55: 是语法错误。你可能想写

if ct == "08:55":

附带说明一下,如果你在 08:54:50 睡了 100 秒,当你醒来时将是 08:56:30,你会想念你的 window。你应该睡不到 1 分钟。