네이버 검색 API를 사용해 네이버 포탈 검색 콘텐츠를 읽어오자
서비스 API 클릭 > 오픈 API 이용 신청 > Application 등록
사용 API 지정 ex: 검색 / 데이터랩(검색어트렌드)/ 데이터랩(쇼핑인사이트)
API 설정 > 환경추가 > WEB설정 > http://localhost
import os
import sys
import urllib.request
client_id = "**네이버 API에서 할당해준 ID**"
client_secret = "**네이버 API에서 할당해준 비번 **"
encText = urllib.parse.quote("파이썬")
# JSON 결과
# search/ 뒤에 book?query=
url = "https://openapi.naver.com/v1/search/book?query=" + encText
# XML 결과
# url = "https://openapi.naver.com/v1/search/blog.xml?query=" + encText
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()
print(response_body.decode('utf-8'))
else:
print("Error Code:" + rescode)
encText = urllib.parse.quote("파이썬")
# JSON 결과
# search/ 뒤에 movie?query=
url = "https://openapi.naver.com/v1/search/movie?query=" + encText
# XML 결과
# url = "https://openapi.naver.com/v1/search/blog.xml?query=" + encText
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()
print(response_body.decode('utf-8'))
else:
print("Error Code:" + rescode)