Code Monkey home page Code Monkey logo

naver-cafe-api's Introduction

동아리 홈페이지 이사

XpressEngine 기반 홈페이지를 네이버 카페로 이전했습니다.

웹 크롤러를 개발하여 기존 게시물을 저장했고, 네이버 카페 API를 활용하여 게시글을 작성했습니다.


웹 크롤링 : web_crawler.py

03년부터 20년까지 축적된 게시물(게시글/댓글)을 추출

BeautifoulSoup, Selenium 활용
SQlite3에 데이터를 저장

  1. DB 연결 & 세팅
  2. ChromeDriver 실행
  3. 로그인
  4. for문으로 게시글 / 댓글 크롤링

네이버 카페 API

'애플리케이션 등록'

사용 API : 카페
서비스 환경 : PC 웹 (로컬에서만 실행)
서비스 URL : http://127.0.0.1:8000/
Callback URL : http://127.0.0.1:8000/

관리자 계정 외에 API 사용 시, 멤버관리에서 ID 추가


2. access token 발급 : get_token.py

  1. 웹에서 사용할 계정으로 로그인
  2. 파일 실행
  3. console 창의 URL 클릭하여, code 값 확인
code = "" // 여기에 추가!
access_token = `` //여기는 계속 비웁니다.
  1. 파일 내 code에 해당 값 추가
  2. 다시 파일 실행
  3. cosnole 창에서 access_token 값 확인

3. 네이버 카페 글쓰기 : naver_write.py

  1. get_token.py 에서 얻은 access_token 값 입력
    token 유효 시간이 1시간이므로 주의
  2. subject, content에 입력하고자 하는 값 추가
  3. 파일 실행

한글 깨짐 현상 : 개발자 센터 코드대로 하면 한글 깨짐 현상이 있다. 아래처럼 코드를 변경하면 정상적으로 인코딩 된다.

//네이버 개발자 센터 API 명세
data = "subject=" + subject + "&content=" + content
request = urllib.request.Request(url, data=data.encode("utf-8"))
// 아래와 같이 변경합니다.
data = urlencode({'subject': subject, 'content': content}).encode()
request = urllib.request.Request(url, data=data)

403 error : 첫 번째 함수는 정상 작동되지만, 두 번째 함수에서 403 error가 발생하는 경우. 함수 호출에 딜레이를 주면 해결할 수 있다. (403 error는 그 외에도 원인이 많음)

for row in cur.execute("SELECT * FROM YB_BOARD_TEST ORDER BY 1 DESC LIMIT 200 OFFSET 1422"):
    naver_upload()
    time.sleep(10) //딜레이 추가

제목, 본문에 " 가 있으면 에러가 발생하는 현상 있음. " 를 ' 로 변경하면 해결할 수 있다

content = urllib.parse.quote(row[4].replace('\"', '\''))

naver-cafe-api's People

Contributors

hi-hj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.