2019-05-16 10:45:31 1556浏览
本篇文章扣丁学堂Python培训小编给读者们分享一下在Python中获取div的文本内容并和想定结果进行对比详解,对Python开发感兴趣的小伙伴就随小编来了解一下吧,希望对小伙伴们有所帮助。
div的内容为:
<div style="background-color: rgb(255, 238, 221);" id="status" class="errors">您输入的用户名或密码有误。</div>
# coding:utf-8
from selenium import webdriver
browser = webdriver.Firefox()
url = 'file:///C:/Users/li/Desktop/hello.html'
browser.get(url)
alert_inf = "您输入的用户名或密码有误。"
s = browser.find_element_by_xpath("//div[@id='status']")
b = s.text
print b
if b.encode('utf-8') == alert_inf:
print "哈哈哈!ok啦!"
else:
print "呀,出错了! 不好玩!"
想要了解更多关于Python开发方面内容的小伙伴,请关注扣丁学堂Python培训官网、微信等平台,扣丁学堂IT职业在线学习教育有专业的Python讲师为您指导,此外扣丁学堂老师精心推出的Python视频教程定能让你快速掌握Python从入门到精通开发实战技能。扣丁学堂Python技术交流群:279521237。
【关注微信公众号获取更多学习资料】 【扫码进入Python全栈开发免费公开课】