Cookie values on different pages of the site after the operation carried login

 

 

 

 

 

For classroom school website, page after login operation only need to bring PHPSESSID cookie or the middle part of that can, with both also, SERVERID do not know is doing, and will change each time the response.

Code:

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':'[email protected]','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())  

 

Guess you like

Origin www.cnblogs.com/wangyi0419/p/11241866.html