我想找出引发异常的数量并将其与 if 语句一起使用。更清楚地说:如果连续引发超过 10 个 TimeoutException,则打印“网站存在问题”。我搜索过,但什么也没找到。我希望有一种有效的方法来做到这一点。
这是代码:
while True:
try:
browser.get("url")
return
except selenium.common.exceptions.TimeoutException:
print "Timeout"
我想做的是:如果引发超过10个超时异常,则打印“网站存在问题”
只需跟踪计数器中引发异常的次数即可。尝试类似的方法:
count = 1
while True:
try:
browser.get("url")
except selenium.common.exceptions.TimeoutException:
count += 1
if count >= 10:
print 'There is a problem with website'
break
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)