1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def get_data(url, rcode, ym, svc_key):
print("service_key", svc_key)
querystring = {
"pageNo":"1",
"startPage":"1",
"numOfRows":"99999",
"pageSize":"10",
"LAWD_CD":"" + rcode + "",
"DEAL_YMD":"" + ym + "",
"type":"json",
"serviceKey":"" + svc_key + ""}
headers = {
'cache-control': "no-cache",
}
print(querystring)
response = requests.request("GET", url, headers=headers, params=querystring)
return response
응답값으로 XML의 값을 넘겨주는데, XML의 값을 Pandas의 DataFrame 형태로 변환
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import xml.etree.ElementTree as ET
import pandas as pd
def parse_xml(text):
root = ET.fromstring(text)
return root
def xml_to_pdf(root):
item_list = []
for child in root.find('body').find('items'):
elements = child.findall('*')
data = {}
for element in elements:
tag = element.tag.strip()
text = element.text.strip()
# print tag, text
data[tag] = text
item_list.append(data)
return pd.DataFrame(item_list)