关于网站登录后的页面操作所携带的不同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())