Api Crawling /Json 형식 데이터 단일/다중 수집 서울 열린데이터 광장
2024. 2. 1. 17:26ㆍData Science/Study 자료
JSON 형식 단일데이터 수집
URL=f'http://openapi.seoul.go.kr:8088/{SERVICE_KEY}/json/tbLnOpendataRtmsV/1/100/'
URL
import requests
import json
import pandas as pd
req = requests.get(URL)
content = req.json() #json데이터 불러오기
result = pd.DataFrame(content['tbLnOpendataRtmsV']['row']) #중요부분
result
다중데이터 수집
공공데이터는 블러올떄 리미트가 걸린 경우들이 많음 서울 열린데이터 광장의 경우 1000개 제한
data = None
SERVICE_KEY ='***********************************'
for j in range(1,5):
url = f'http://openapi.seoul.go.kr:8088/{SERVICE_KEY}/json/tbLnOpendataRtmsV/{1+((j-1)*1000)}/{j*1000}'
# url = f'http://openapi.seoul.go.kr:8088/{service_key}/json/tbLnOpendataRentV/1/1000/2023/11560'
print(url)
#하나의 URL을 Json으로 받아 데이터 프레임으로 만듦
req = requests.get(url)
content = req.json()
con = content['tbLnOpendataRtmsV']['row']
result = pd.DataFrame(con)
data = pd.concat([data, result])
data = data.reset_index(drop=True)
data.head()
for문과 f포멧팅을 이용하여 가져올 데이터수를 조정할수 있다
'Data Science > Study 자료' 카테고리의 다른 글
[UX/UI특강] 멀티캠퍼스UX/UI특강을 들으며/ 문고리 디자인 해보기 (0) | 2024.02.03 |
---|---|
뽐뿌 핫딜 데이터 크롤링/ csv파일 뽑기 코드 리뷰 (0) | 2024.02.01 |
[Streamlit] tab과 col 명령어 (1) | 2024.01.30 |
[Streamlit] sidebar활용 (0) | 2024.01.30 |
[Streamlit] st.write/ 마크다운 사용하기 (0) | 2024.01.29 |