Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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 31
Archives
Today
Total
관리 메뉴

hong_mok

[Python] requests 모듈 사용하여 api 활용하기 본문

Python

[Python] requests 모듈 사용하여 api 활용하기

moki 2022. 2. 17. 03:04
# https://api.agify.io/?name=hong

# requests 불러오기
import requests

# 나이 예측 api 사용
# 특정 이름을 입력 했을 때, 무작위 나이를 가져와서
name = input("이름을 입력하세요 : ")
url = f"https://api.agify.io/?name={name}"
response = requests.get(url).json()

# ~~의 나이는 ~~살 입니다. 라는 문자 출력
print(f"{name}의 나이는 {response['age']}살 입니다.")

Comments