반응형
  • TISTORY 오픈 API 앱 등록.

 

TISTORY 오픈 API 설정

 

- 앱 등록

  서비스 명 입력

  서비스 URL 및 CallBack에 TISTORY 주소 입력한다.

  등록

 

TISTORY OPEN API APP등록

 

 

등록 완료 후 App ID 및 Secret Key 사용 가능.

 

TISTORY APPID 및 Secret Key 확인 가능.

 

위의 정보들이 Python에서 필요하다.

앱 등록 시 입력한 정보로 아래 값 설정.

g_client_id = 
g_redirect_uri = 

g_user_id = 
g_password =

 

Python 소스

import requests import json import re #Open API 앱 등록후 App 아이디 설정 g_client_id = {App ID} #Open API 앱 등록후 입력한 CallBack 설정 g_redirect_uri = {CallBack} g_oauth_url = "https://www.tistory.com/oauth/authorize?client_id="+g_client_id+"&redirect_uri="+g_redirect_uri+"&response_type=token" #TISTORY ID g_user_id = {TISTORY ID} #TISTORY PASSWORD g_password = {TISTORY PASSWORD} print(g_oauth_url) res = requests.get(g_oauth_url) print(res.status_code) print(res.headers['Set-Cookie']) kakao_cookie = res.headers['Set-Cookie'].replace("; path=/",'') print(kakao_cookie) print(res.url) headers = { 'Accept' : 'text/html, application/xhtml+xml, image/jxr, */*', 'Accept-Encoding' : 'gzip, deflate', 'Accept-Language' : 'ko, en-US; q=0.8, en; q=0.6, zh-Hans-CN; q=0.4, zh-Hans; q=0.2', 'Cache-Control' : 'no-cache', 'Connection' : 'Keep-Alive', 'Content-Type' : 'application/x-www-form-urlencoded', 'Cookie' : kakao_cookie, 'Host' : 'www.tistory.com', 'Referer' : res.url, 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko' } login_data = { 'fp' : 'a668ac102f81b86f521c07dfb6dc992c', 'keepLogin' : 'on', 'loginId' : g_user_id, 'password' : g_password, 'redirectUrl' : res.url } res = requests.post('https://www.tistory.com/auth/login', headers=headers, data=login_data) print(res.url) match = re.match('(.*?)access_token=(?P<access_token>.*?)&state=', res.url) gd = match.groupdict() access_token = gd['access_token'] print(access_token)

 

python 실행 후 access token 확인

 

 

TISTORY Access Token 확인.

반응형
반응형

쇼핑몰의 상품명과 상세설명, 이미지주소와 제품링크를 긁어오게 해놓았습니다.

 

from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("https://www.olympick.co.kr/goods/goods_view.php?goodsNo=1000000011")  
bsObject = BeautifulSoup(html, "html.parser") 

title=bsObject.head.title
contents=(bsObject.head.find("meta", {'name':'description'}).get('content'),bsObject.head.find("meta", {'property':'og:url'}).get('content'),\
          bsObject.head.find("meta", {'property':'og:image'}).get('content'),(bsObject.head.find("meta", {'name':'keywords'}).get('content')))

print(title)
print(contents)
반응형

'파이썬 여바라' 카테고리의 다른 글

TISTORY Python 자동으로 Access Token 받아오기  (0) 2020.05.25

+ Recent posts