使用post请求登陆
1.使用post请求登陆
import requests
import matplotlib.pyplot as plt
url = 'https://www.ptpress.com.cn/login'
# data = {'username': '15976318994', 'password': '15976318994', 'verifyCode': '7ybnn',}
In [ ]:
code_url = 'https://www.ptpress.com.cn/kaptcha.jpg'
In [ ]:
# Session回话
sess = requests.Session()
rq_code = sess.get(code_url) # 对验证码的网页进行请求发送
with open('./code.jpg', 'wb') as f:
f.write(rq_code.content)
In [ ]:
def get_code():
pic = plt.imread('./code.jpg') # image_read读取图片
plt.imshow(pic) # 展示图片
plt.show()
return input('>>> ')
get_code()
In [ ]:
code = get_code()
In [ ]:
login_data = {'username': '15976318994', 'password': '15976318994', 'verifyCode': code}
login_data
In [ ]:
rq = sess.post(url, data=login_data)
In [ ]:
print(rq.url)
2.参考文章
【创作不易,望点赞收藏,若有疑问,请留言,谢谢】