zoukankan      html  css  js  c++  java
  • 关于网站登录后的页面操作所携带的不同cookie值

    对于课堂派网站,登录后的页面操作只需要携带PHPSESSID或者cookie中间那部分即可,两个都带也可,SERVERID不知道是干啥的,每次响应的都会变.

    代码实现:

    cookie = None
    class HttpRequest:
        def __init__(self,method,url,data=None):
            self.method=method
            self.url=url
            self.data=data
        # def http_get(self):
        #     res=requests.get(self.url,params=self.data)
        #     print(res)
        #     print(res.text)
        # def http_post(self):
        #     res = requests.post(self.url, data=self.data)
        #     print(res)
        #     print(res.text)
        def send_request(self):
            global cookie
            if self.method=='get':
                coo={'ketangpai_home_remember':'think%3A%7B%22username%22%3A%22MDAwMDAwMDAwMLOGrZWHuc2whLiKmLG6etmZtmfOk2RhbQ%22%2C%22expire%22%3A%22MDAwMDAwMDAwMLOGuZaG39FthrigmbGmdZ4%22%2C%22token%22%3A%22MDAwMDAwMDAwMMurrpWavLehhs1-3LOpkZOD3ZmVepuomcWmmqaMiHtnr5ylzYWosKKZq6HQxtOK0ZCme5p-q6iZu2yrn4uNhJ3KedDYk7ivboS4ipax36OWhbedmX56YW0%22%7D', 'expires':'Wed, 24-Jul-2019 23:26:30 GMT','path':'/'}
                res=requests.get(self.url, params=self.data,verify=False,cookies=coo)
                cookie = res.cookies  # 更新cookie
            else:
                res=requests.post(self.url, data=self.data,verify=False,cookies=cookie)
                cookie = res.cookies
            return res
    
    
    if __name__ == '__main__':
    
        url='https://www.ketangpai.com/UserApi/login'
        data={'email':'1255811581@qq.com','password':'huahua90!@'}
        # h=HttpRequest('post',url,data)
        # res = h.send_request()
        # print(res)
        # print(res.cookies)
    
        # print(res.cookies.items())
        # print(type(res.cookies.items()))
        # cookie_str=''
        # cookie_dict = {}
        # cookie_list = []
        # for key, value in res.cookies.items():
        #     cookie_str += key + '=' + value + ';'
        #     cookie_dict[key]=value
        #     cookie_list.append(key+'='+value)
        # print(cookie_str)
        # print(cookie_dict)
        # print(cookie_list)
    
        h=HttpRequest('get','https://www.ketangpai.com/HomeworkApi/listsHomework?courseid=MDAwMDAwMDAwMLOcqZWH37Np')
        res2 = h.send_request()
        print('访问作业接口的结果是:',res2)
        print(res2.cookies)
        print(res2.text)
    
        print(res2.json())  
  • 相关阅读:
    剑指offer-面试题23.从上往下打印二叉树
    C++静态成员函数不能调用非静态成员变量
    程序的堆区和栈区
    C++空类的大小
    struct内存对齐
    LeeCode(Database)-Customers Who Never Order
    LeeCode(Database)-Duplicate Emails
    LeeCode(Database)-Employees Earning More Than Their Managers
    LeeCode(Database)-Combine Two Tables
    剑指offer-面试题22.栈的压入,弹出序列
  • 原文地址:https://www.cnblogs.com/wangyi0419/p/11241866.html
Copyright © 2011-2022 走看看