我有一个jenkins工作,运行15至30分钟。我想检查page_source中的文本“成功”或“失败”。 如果两者都不存在,我想每十秒刷新一次并再次检查。请指导我。我正在使用python-selenium 到目前为止,这是我的剧本。
src = driver.page_source
success = re.search(r'Finished: SUCCESS', src)
failure = re.search(r'Finished: FAILURE', src)
if success:
print ('success')
if failure:
print ('failure')
else:
driver.refresh()
time.sleep(5)
答案 0 :(得分:1)
你错过了再次调用re.search。您可以将搜索内容包装在函数中并使用递归。
def foo():
src = driver.page_source
success = re.search(r'Finished: SUCCESS', src)
failure = re.search(r'Finished: FAILURE', src)
if success:
print ('success')
if failure:
print ('failure')
else:
driver.refresh()
time.sleep(5)
foo() ## your function gets called again
foo() ## call your function for the first time