Skip to content

Commit 86e1be1

Browse files
author
=
committed
260112 - json query 실습 (요일별 웹툰 제목 & 별점 커스텀 딕셔너리 생성)
1 parent c388beb commit 86e1be1

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/test.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,28 @@
44

55
class WebResponse:
66
def __init__(self):
7-
pass
7+
self.default_site = ""
8+
self.headers = {}
9+
self.datas = {}
810

911
def response_html(self, site = None, header = None):
1012
target_url = site if site else self.default_site
11-
13+
# print(header)
1214
try:
1315
response = requests.get(target_url)
1416
response.raise_for_status()
1517
json_data = json.loads(response.content)
1618
week = [*json_data["titleListMap"].keys()]
1719
for w in week:
20+
data_title, data_score = [], []
1821
contents =[*json_data['titleListMap'][w]]
19-
print(f"\n ===== 요일 : {w} ====== \n")
22+
# print(f"\n ===== 요일 : {w} ====== \n")
2023
for i in contents:
21-
print(f"제목 : {i['titleName']} , 별점 = {round(i['starScore'],2)} 점")
22-
return json_data
24+
# print(f"요일 : {w}, 제목 : <<{i['titleName']}>> , 별점 = {round(i['starScore'],2)} 점")
25+
data_title.append(i['titleName'])
26+
data_score.append(i['starScore'])
27+
self.datas[w] = {'title' : data_title, 'score' : data_score}
28+
return self.datas
2329

2430
except requests.exceptions.RequestException as e:
2531
print(f"Error = {e}")

0 commit comments

Comments
 (0)