• 基于表单登录的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.参考文章

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

  • 相关阅读:
    div minheight
    tomcat启动时doc窗口一闪而过的解决方法
    积分题05012014
    LaTeX技巧001:LaTeX中输入大小写罗马数字
    积分题1之来自G.Han的一道积分题
    LaTeX测试
    header函式的使用
    PHP中如何调用webservice
    在C++Builder中开发CGI的一点点体会
    PHP教程.经验技巧(中)
  • 原文地址:https://www.cnblogs.com/dongxuelove/p/16434840.html
Copyright © 2020-2023  润新知