#! /usr/bin/python # coding:utf-8 #导入requests库 import requests #获取会话 s = requests.session() #创建登录数据 data={'uid':'admin','passw':'admin'} #利用登录数据登录指定登录页面url res = s.post('http://demo.testfire.net/bank/login.aspx',data); #抓取的页面 resOK = s.get('http://demo.testfire.net/bank/main.aspx'); #利用变量+text将页面内容打印出来 print resOK.text
执行结果:用户admin已在欢迎页面显示出来,说明登录成功。
注意事项:
(1)在创建登录数据时,uid与passw这两个变量名要与实际登录页面的变量名称相同才能提交登录,如下图所示
(2)将抓取的页面打印时一定要使用变量+text的方式打印,否则只会打出http状态码
<Response [200]>