반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 파이썬 네이버 로그인
- 파이썬네이버부동산
- pywinauto
- 파이썬 가상환경 설치
- vscode venv 설치
- Uipath 기초
- selenium
- pycdas.exe
- pycdc.exe
- 네이버 로그인 캡챠해결
- 파이썬 가상환경 설치방법
- pywinauto 윈도우제어
- 네이버 로그인 영수증 해결
- 네이버매물크롤링
- 네이버부동산크롤링
- Uipath 설치방법
- Selenium 셀렉터잡기
- 가상환경설치
- uipath 입문
- Python
- 날짜 정규식
- 파이썬 환경설정
- 네이버 로그인 하기
- UiPath
- 왕초보 파이썬 실행
- Element is not clickable at point
- 커머스API
- venv 설치
- 네이버커머스API
- pywinauto 윈도우
Archives
- Today
- Total
콘솔워크
네이버 API 책 검색 샘플 코드 본문
반응형
if 1 == 1:
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
import urllib.request
class APIPracticeBot:
def __init__(self) -> None:
self.client_id = ""
self.client_secret = ""
self.url = "https://openapi.naver.com/v1/search/book?query="
def my_client_info(self):
print(f"{self.client_id} {self.client_secret}")
def get_search_url(self, keyword=""):
print(f"검색어: {keyword}")
enc_keyword = urllib.parse.quote(f"{keyword}")
search_url = self.url + enc_keyword
print(search_url)
return search_url
def naver_request(self, url_query):
request = urllib.request.Request(url_query)
request.add_header("X-Naver-Client-Id", self.client_id)
request.add_header("X-Naver-Client-Secret", self.client_secret)
return request
def naver_response(self, request):
response = urllib.request.urlopen(request)
rescode = response.getcode()
print(f"{response} {rescode}")
if rescode == 200:
response_body = response.read()
print(response_body.decode("utf-8"))
else:
print("Error Code:" + rescode)
return response_body
def work_start(self, keyword=""):
self.my_client_info()
url_query = bot.get_search_url(keyword)
request = self.naver_request(url_query)
response_body = self.naver_response(request)
if __name__ == "__main__":
keyword = "검색어"
bot = APIPracticeBot()
bot.work_start(keyword)
client_id와 client_secret은 해당 링크에서 발급 받으실 수 있습니다.
https://developers.naver.com/docs/common/openapiguide/appregister.md
사전 준비 사항 - Open API 가이드
사전 준비 사항 네이버 오픈API를 사용하려면 먼저 네이버 개발자 센터에서 애플리케이션을 등록하고 클라이언트 아이디와 클라이언트 시크릿을 발급받아야 합니다. 클라이언트 아이디와 클라
developers.naver.com
반응형
'프로그래밍 > python' 카테고리의 다른 글
배열에서 맨 앞의 요소를 2개씩 비교하여 중복 제거하기 (0) | 2022.11.07 |
---|---|
[pyqt5] vscode에서 멀티스레드 사용 시 중단점에서 멈추지 않는 현상 수정 (0) | 2022.11.02 |
Dictionary 기본 (0) | 2022.10.27 |
대괄호 안의 문자 추출 (0) | 2022.10.26 |
현재 페이지에 alert가 있는지 검증해보는 except (0) | 2022.10.24 |