19. Python - JSON Parsing
2021. 2. 25. 00:12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | from urllib.parse import quote from http.client import HTTPSConnection from json import loads # # JSON Parsing # https://developers.kakao.com/docs/latest/ko/daum-search/common # l = [1, 2, 3] # Python : List , JS : array # d = {"height" : 180, "weight" : 80} # Python : dict , JS : object # 검색어 입력받기, 한글 처리 q = quote(input("뭐 : ")) # 요청헤더 설정 h = {"Authorization": "KakaoAK ID"} hc = HTTPSConnection("dapi.kakao.com") hc.request("GET", "/v2/search/web?query=" + q, headers=h) resBody = hc.getresponse().read() # JSON Parsing kakaoBlog = loads(resBody) print(type(kakaoBlog)) # <class 'dict'> blogs = kakaoBlog["documents"] for b in blogs: print(b["title"]) print(b["contents"]) print("----------") | cs |
'Python' 카테고리의 다른 글
20. Python - Web Crawling (0) | 2021.02.25 |
---|---|
18. Python - XML Parsing2 (0) | 2021.02.24 |
17. Python - XML Parsing1 (0) | 2021.02.24 |
16. Python - Exception (0) | 2021.02.24 |
15. Python - 다중상속 (0) | 2021.02.23 |