import os
import sys
import urllib.request
import json
import re

def naver_blog_search(client_id, client_secret, text):
    encText = urllib.parse.quote(text)
    url = "https://openapi.naver.com/v1/search/blog?query=" + encText # json 결과
    # url = "https://openapi.naver.com/v1/search/blog.xml?query=" + encText # xml 결과
    request = urllib.request.Request(url)
    request.add_header("X-Naver-Client-Id",client_id)
    request.add_header("X-Naver-Client-Secret",client_secret)
    response = urllib.request.urlopen(request)
    rescode = response.getcode()
    if(rescode==200):
        response_body = response.read()
        return response_body.decode('utf-8')
    else:
        print("Error Code:" + rescode)
    
def striphtml(data):
    p = re.compile('<.*?>')
    return p.sub('', data)

naver_result = naver_blog_search('OJgN42xxZiJXpnZtCH1j', 'crXggqJhhW', '코딩')
y = json.loads(naver_result)
print(y)
print(y['items'])