05-02 08:47
Recent Posts
Recent Comments
관리 메뉴

너와나의 관심사

아파트 실거래가 파이썬 크롤링 본문

카테고리 없음

아파트 실거래가 파이썬 크롤링

벤치마킹 2019. 2. 12. 21:42

아파트 실거래가를 매일 매일 크롤링하는 코드 작성 및 블로그에 올리는 프로젝트 한번 해볼까 한다.


우선 파이썬으로  www.data.go.kr 에 있는 아파트 분양권 실거래가 조회 하는 크롤링 데이터 까지느 했는데.. 

파싱을 좀더 해서 엑셀로 만드는 작업을 해야겠음 



#-*-coding:utf-

import urllib.request
import requests
import json
import logging
from pprint import pprint
from bs4 import BeautifulSoup
from urllib.request import urlopen
import xml.etree.ElementTree as elemTree
import re


ServiceKey =
Time = "201902"
Location = "41465" #풍덕천동

url = "http://openapi.jejutour.go.kr:8080/openapi/service/TourSpotInfoService/getTourSpotList?serviceKey=" + ServiceKey + "&CAT=TU02&numOfRows=100&_type=json"


url2 = "http://openapi.molit.go.kr/OpenAPI_ToolInstallPackage/service/rest/RTMSOBJSvc/getRTMSDataSvcSilvTrade?LAWD_CD=" + Location + "&DEAL_YMD=" + Time + "&serviceKey=" + ServiceKey
url3 = "http://openapi.molit.go.kr:8081/OpenAPI_ToolInstallPackage/service/rest/RTMSOBJSvc/getRTMSDataSvcRHTrade?LAWD_CD=11110&DEAL_YMD=201901&serviceKey=" + ServiceKey

req = urllib.request.Request(url2)
try:
res = urllib.request.urlopen(req)

except UnicodeEncodeError:
print('[OpenAPI] UnicodeEncodeError')


data = res.read().decode('utf-8')

soup = BeautifulSoup(data, 'html.parser')
print (soup)


#if (soup.resultcode.string != '00'):
# print('[OpenAPI] ', soup.resultmsg.string)

items = (soup.findAll('item'))
#items = re.sub('[&lt]', '', items, 0).strip()
print(items)
for name in items:
text = name.get_text()
text = text.replace("<", ", ")
text = text.replace(",", "",1)
text = text.replace(">", ":")
print(text)


Comments