■ get 함수를 사용해 HTTP GET 요청을 처리하는 방법으로 보여준다.
▶ 예제 코드 (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 |
import requests 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 = requests.get(url = "http://google.com") printResponse("requests.get 호출 결과", response) """ requests.get 호출 결과 response : <Response [200]> response.url : http://www.google.com/ response.headers['content-type'] : text/html; charset=ISO-8859-1 response.encoding : ISO-8859-1 response.status_code : 200 """ |
▶ requirements.txt
1 2 3 4 5 6 7 |
certifi==2024.6.2 charset-normalizer==3.3.2 idna==3.7 requests==2.32.3 urllib3==2.2.1 |