网络编程
位置:首页>> 网络编程>> Python编程>> 在python中获取div的文本内容并和想定结果进行对比详解

在python中获取div的文本内容并和想定结果进行对比详解

作者:请叫我怪兽_谢谢  发布时间:2021-09-05 07:29:37 

标签:python,div,文本

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 "呀,出错了! 不好玩!"

来源:https://blog.csdn.net/MiaoDaLengShui/article/details/51683387

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com