■ Response 클래스의 cookies 변수를 사용해 HTTP 응답시 쿠키 값을 구하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import httpx def printResponse(title, response): print(title ) print(f" response : {response}" ) print(f" response.url : {response.url}" ) print(f" response.headers['content-type'] : {response.headers['content-type']}") print(f" response.encoding : {response.encoding}" ) print(f" response.status_code : {response.status_code}" ) #print(f" response.text : {response.text}" ) print() response = httpx.get('https://httpbin.org/cookies/set?chocolate=chip') printResponse("응답시 쿠키 값 구하기", response) print(f" response.cookies['chocolate'] : {response.cookies['chocolate']}") """ 응답시 쿠키 값 구하기 response : <Response [302 FOUND]> response.url : https://httpbin.org/cookies/set?chocolate=chip response.headers['content-type'] : text/html; charset=utf-8 response.encoding : utf-8 response.status_code : 302 response.cookies['chocolate'] : chip """ |