python 用selenuim判断页面是否全部加载完成,并且加上最大时长,超过时长报错
STR_READY_STATE = '' time_start = time.time() while STR_READY_STATE != 'complete': time.sleep(0.001) STR_READY_STATE = driver.execute_script('return document.readyState') time_end = time.time() if int(time_end - time_start) > 60: raise MyException("hpl 页面打开 超过60s")
异常类
class MyException(Exception): def __init__(self, *args): self.args = args