【发布时间】:2019-05-03 08:14:31
【问题描述】:
我正在尝试捕获一个错误,该错误将重新启动我的程序并更改代理,但我无法捕获该错误,因为它像这样存储并且类是动态命名的:
<p class="g4Vm4">By signing up, you agree to our <a target="_blank" href="https://help.instagram.com/581066165581870">Terms</a> . Learn how we collect, use and share your data in our <a target="_blank" href="https://help.instagram.com/519522125107875">Data Policy</a> and how we use cookies and similar technology in our <a target="_blank" href="/legal/cookies/">Cookies Policy</a> .</p>
所以我试图通过这个函数捕获 xpath,但我无法这样做。
def has_error(browser):
try: #/*[contains(text(), 'technology')]/html/body/span/section/main/div/article/div/div[1]/div/form/p"
browser.find_element_by_xpath("/html/body//*[contains(text(),'technology')]")
return False
except: return True
if not has_error(browser):
print('Error found! , aborted!')
browser.quit()
os.execv(sys.executable, ['python'] + sys.argv)
【问题讨论】:
标签: python-3.x selenium selenium-webdriver automation