#使用cookie登录Tpshop [成功]

任务1:利用cookie登录

#使用cookie登录Tpshop [成功]
# 1.发送验证码请求
url_verify = "http://localhost/index.php?m=Home&c=User&a=verify"
r = requests.get(url_verify)
with open("E://download/png1.png","wb") as f:
    f.write(r.content)
cookies_ver = r.cookies
print(cookies_ver)

# 2.发送登录请求:携带cookie信息
url = "http://localhost/index.php?m=Home&c=User&a=do_login"
data = {"username":"13800138006","password":"123456","verify_code":"8888"}
r = requests.post(url,data=data,cookies=cookies_ver)
print(r.json())

# 3.打印登录后页面的某个显眼信息
url_list = "http://localhost/index.php/Home/Order/order_list.html"
r = requests.get(url_list,cookies=cookies_ver)
print(r.text)

#使用cookie登录Tpshop [成功]_第1张图片

任务2:利用session登录

# 创建session对象
session = requests.session()
# 1.发送登录请求,获取cookie
url_verify = "http://localhost/index.php?m=Home&c=User&a=verify"
r = session.get(url_verify)
# 2.发送登录请求:携带cookie信息
url = "http://localhost/index.php?m=Home&c=User&a=do_login"
data = {"username":"13800138006","password":"123456","verify_code":"8888"}
r = session.post(url,data=data)
print(r.json())
# 3.验证是否登录成功,打印登录后页面的某个显眼信息
url_value = "http://localhost/index.php/Home/Order/comment.html"
r = session.get(url_value)
print(r.text)

#使用cookie登录Tpshop [成功]_第2张图片

你可能感兴趣的:(windows,selenium,postman)