在我的python Selenium代码中,我应该使用manytry-catch来传递错误,如果不使用它,我的脚本将无法继续。
例如,如果我不使用try-catch,如果我的脚本没有找到desc span
,我将出现一个错误,我无法继续
try :
libelle1produit = prod.find_element_by_css_selector(('.desc span')).text # libelle1produit OK
except:
pass
有没有传递错误的替代方法?在
Tags:
是的,为了避免
try-catch
并避免错误,请尝试使用find_elements
来代替它,它将返回带有匹配定位器的所有元素的列表或空列表(如果找不到任何内容),则只需检查列表长度以确定元素是否存在,如下所示:相关问题 更多 >
编程相关推荐