大佬教程收集整理的这篇文章主要介绍了Selenium 无法通过 else 语句获取元素原因,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这个问题的追求:Instagram have 2 type of xpath? How it could be remedied?我没有解决我的employees = table(
"employee",Base.Metadata,# Todo set consTraints for status
column("ID",Integer,priMary_key=True,nullable=False),column("email",String,unique=True,nullable=TruE),column("owner_ID",default=NonE),column("hashed_password",column("role",# # # RELATIONSHIPS # # #
column("owner_ID",ForeignKey("Employee.id"))
)
sqlAlchemy 1.4.4
psycopg2 2.8.6
asyncpg 0.22.0
什么时候获得“私人资料”
它返回一个错误:
我的代码:
else-statement
感谢您的支持
您可以使用 try... except
代替 if... else
。在您的情况下,它可能是:
for follower in followers:
#IteratE into the list
browser.get(follower)
sleep(2)
try:
browser.find_elemenT_By_css_SELEctor("li:nth-of-type(2) a.-nal3 span").get_attribute("title"):
print("Public profil")
except:
print("private profil")
conTinue
,
您需要在循环中用 if..else
块替换 try/except
子句。这样,如果在每个循环中都没有找到元素,它就不应该崩溃
NoSucHelementexception
如果您想在到达私人配置文件后停止循环,只需在第二个 for follower in followers:
#IteratE into the list
browser.get(follower)
sleep(2)
try:
browser.find_elemenT_By_css_SELEctor("li:nth-of-type(2) a.-nal3 span").get_attribute("title"):
print("Public profil")
except NoSucHelementexception:
print("private profil")
语句后添加一个 break
要在脚本顶部添加的包:
print()
以上是大佬教程为你收集整理的Selenium 无法通过 else 语句获取元素原因全部内容,希望文章能够帮你解决Selenium 无法通过 else 语句获取元素原因所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。