개발일지/Python
Requests 라이브러리
E-room
2022. 7. 5. 16:41
728x90
Requests 함수를 사용하려면
Requests 라이브러리를 설치해야한다.
서울시 대기 OpenAPI에서, 모든 구의 IDEX_MVL 값을 가져온다.
import requests # requests 라이브러리 설치 필요
r = requests.get('http://spartacodingclub.shop/sparta_api/seoulair')
rjson = r.json()
gus = rjson['RealtimeCityAir']['row']
for gu in gus:
print(gu['MSRSTE_NM'], gu['IDEX_MVL'])
IDEX_MVL 값이 60미만인 구만 가져온다.
import requests # requests 라이브러리 설치 필요
r = requests.get('http://spartacodingclub.shop/sparta_api/seoulair')
rjson = r.json()
gus = rjson['RealtimeCityAir']['row']
for gu in gus:
if gu['IDEX_MVL'] < 60:
print (gu['MSRSTE_NM'], gu['IDEX_MVL'])
728x90