네이버 황금키워드 추출에 필요한 검색량 조회 API 사용방법
황금키워드를 찾기 위해 네이버 검색량 API를 사용하는데 필요한 코드를 공유합니다. 자세한 내용은 아래 영상 및 코드를 참고하세요 <iframe src="https://www.youtube.com/embed/fSAfvQjuBtg" title="YouTube 영상" al
황금키워드를 찾기 위해 네이버 검색량 API를 사용하는데 필요한 코드를 공유합니다.
자세한 내용은 아래 영상 및 코드를 참고하세요
아래 코드에서 사용자 정보, 키워드 등을 수정하여 사용하세요.
| 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import hashlib import hmac import base64 import time import requests # 서명 생성 def generate_signature(timestamp, method, uri, secret_key): message = "{}.{}.{}".format(timestamp, method, uri) hash = hmac.new(bytes(secret_key, "utf-8"), bytes(message, "utf-8"), hashlib.sha256) hash.hexdigest() return base64.b64encode(hash.digest()) ############################# # 사용자 정보 API_KEY = "" SECRET_KEY = "" CUSTOMER_ID = "" # 키워드 keyword = '캠핑' ############################# # 요청 정보 BASE_URL = 'https://api.searchad.naver.com' uri = '/keywordstool' url = BASE_URL + uri method = 'GET' keyword = keyword.replace(' ', '') params = {'hintKeywords': keyword, 'showDetail': 1} # 서명 생성 timestamp = str(round(time.time() * 1000)) message = "{}.{}.{}".format(timestamp, method, uri) hash = hmac.new(bytes(SECRET_KEY, "utf-8"), bytes(message, "utf-8"), hashlib.sha256) hash.hexdigest() signature = base64.b64encode(hash.digest()) # 헤더 headers = { 'Content-Type': 'application/json; charset=UTF-8', 'X-Timestamp': timestamp, 'X-API-KEY': API_KEY, 'X-Customer': CUSTOMER_ID, 'X-Signature': signature } # API 요청 response = requests.get(url, params=params, headers=headers) data = response.json() # 결과 출력 for k in data['keywordList']: pc_cnt = k['monthlyPcQcCnt'] if k['monthlyPcQcCnt'] != '< 10' else 0 mo_cnt = k['monthlyMobileQcCnt'] if k['monthlyMobileQcCnt'] != '< 10' else 0 sum_cnt = pc_cnt + mo_cnt print(k['relKeyword'], sum_cnt) Colored by Color Scripter | cs |