抓取接口返回的cookie

前提

因业务需要,需要使用登录后的接口cookie进行其它接口测试。

构思

使用python中的requests库进行cookies保存

流程

import requests
_data = {"username":"username","password":"password"}
_url = ('https://sso.360che.com/index.php?c=login&m=login&platform=app&auth=1')
r = requests.post(_url, data=_data)
# print (r.text)
_cookies = r.cookies
print (_cookies)

结果

<RequestsCookieJar[<Cookie AbcfN_ajaxuid=524983 for .360che.com/>, <Cookie AbcfN_auth=98344XeFN4oncF35p8OQjBv1ZaibBXNtM3%2BK7BuzAFMzQ1NM1Y0zH4CFbfThjXGeO7hcrcGGqEPjuad6%2BoaC7jEn5xU for .360che.com/>, <Cookie AbcfN_avatar=https%3A%2F%2Fi.kcimg.cn%2Fdata%2Favatar%2Fnew%2F83%2Fdd10a2665b00496694cec18cbb65edca_big.jpg-80x80.jpg for .360che.com/>, <Cookie AbcfN_nickname=%E5%A3%B9%E8%B4%B0%E5%8F%81%E8%82%86%E4%BC%8D%E9%99%86%E6%9F%92%E6%8D%8C%E7%8E%96%E6%8B%BE for .360che.com/>, <Cookie AbcfN_referer=http%253A%252F%252Fwww.360che.com%252F for .360che.com/>, <Cookie AbcfN_userid=test1088 for .360che.com/>]>
[Finished in 1.1s]

引用

https://blog.csdn.net/crisschan/article/details/51012387

猜你喜欢

转载自blog.csdn.net/bjxingmeng/article/details/81740581