基于表单登录的cookies登录

1.基于表单登录的cookies登录

In [ ]:

import requests
import matplotlib.pyplot as plt
from http.cookiejar import LWPCookieJar

s = requests.Session()

s.cookies = LWPCookieJar('cookie')
url = 'http://www.tipdm.org/login.jspx'

login = {'username': 'pc2019',
         'password': 'pc2019',
         }
rqq = s.post(url, data=login)
print(rqq.url)  # 检测正常登录
s.cookies.save(ignore_discard=True, ignore_expires=True)  # save cookies

In [ ]:

s.cookies.load(ignore_discard=True, ignore_expires=True)

In [ ]:

s.get('http://www.tipdm.org/member/index.jspx').content.decode('utf8')

2.人民邮电网站 (此网站有验证码)

In [ ]:

import requests
import matplotlib.pyplot as plt
from http.cookiejar import LWPCookieJar

s = requests.Session()

s.cookies = LWPCookieJar('cookie')


url = 'https://www.ptpress.com.cn/login'

rqq = s.get('https://www.ptpress.com.cn/kaptcha.jpg')
with open('./captcha.jpg', 'wb') as f:
    f.write(rqq.content)

pic = plt.imread('./captcha.jpg')
plt.imshow(pic)
plt.show()
a = input('请输入验证码:')

login = {'username': 'pc2019',    # 请切换自己的用户名和密码
         'password': 'pc2019',
         'verifyCode': a}
rqq = s.post(url, data=login)
print(rqq.url)  # 检测正常登录
s.cookies.save(ignore_discard=True, ignore_expires=True)  # save cookies

3.参考文章

【创作不易,望点赞收藏,若有疑问,请留言,谢谢】

posted @ 2022-07-01 15:33  东血  阅读(154)  评论(0编辑  收藏  举报

载入天数...载入时分秒...