Python怎样抓取当前页面HTML内容?

在登录界面,登陆账号密码,还有验证码,当输入错误时网页HTML语句是
<span class="tips" id="imgStatus" style="color: green;">验证码错误</span>
输入正确时:
<span class="tips" id="imgStatus" style="color: green;">验证码输入正确</span>
我想在当前页面抓取html这条语句中的“验证码错误”“验证码输入正确”应该怎样去抓取?
我的想法是:
r = re.compile(r'">(.*?)\</span\>')
T = r.search(u'<span id="phoneCodestatus" style="color: green;">输入正确</span>').group(1)
F = r.search(u'<span id="phoneCodestatus" style="color: red;">验证码错误</span>').group(1)
是否正确?

第1个回答  2017-09-19
当然这样子也是可以的,不过通用点的方法是用beautifulsoup库去定位id=phoneCodestatus