Naver API

네이버 API 사용 준비 사항


Naver 검색 API 활용

책 isbn, title 수집

import requests

url = 'https://openapi.naver.com/v1/search/book.json'

with open('./data/naver-api.txt', 'r') as f:
    info = f.readline().split()
    nId = info[0]
    nSecret = info[1]

headers = {
    'X-Naver-Client-Id': nId,
    'X-Naver-Client-Secret':nSecret
}
params = {'query':'파이썬','display':'10'
          ,'start':'1','sort':'sim'}

response = requests.get(url, headers=headers, params=params)

if response.status_code == 200:
    data = response.json()

items = data['items']
isbn_list = []
title_list = []
for d in items:
    #print(d['isbn'])
    #print(d['title'])
    isbn_list.append(d['isbn'])
    title_list.append(d['title'])

book_info = dict(list(zip(isbn_list, title_list)))
print(book_info)

연습