티스토리 블로그 계정과 연동해 자동 발행을 해보자. 티스토리 API 발행 및 사용법은 인터넷에 검색하면 쉽게 찾을 수 있는데, 귀찮으면 티스토리 API 공식 페이지를 참고하자. (https://tistory.github.io/document-tistory-apis/)
[YES24 자료 추출 및 크롤링 사용법은 이전 포스팅 참고]
YES24 종합 베스트 크롤링과 각 분야별 베스트 페이지 구성이 동일하여 각 URL만 변경하면 소스 변경없이 데이터 추출이 가능한다. 여기에 티스토리 계정을 연동하면 자동 발행이 가능하다.
소스는 다음과 같다.
from base64 import encode
import tistoryAPI
import requests
from bs4 import BeautifulSoup
import datetime as dt
if __name__ == "__main__":
# YES24 자기계방 분양 종합 베스트
url = 'http://www.yes24.com/24/category/bestseller?CategoryNumber=001001026&sumgb=06'
response = requests.get(url)
if response.status_code == 200:
html = response.text
soup = BeautifulSoup(html, 'html5lib')
else :
print(response.status_code)
x = dt.datetime.now()
today = str(x.year) + '-' + str(x.month) + '-' + str(x.day)
blog_name = "블로그명"
t_title = "YES24 자기계발 베스트 셀러 Top 10 (" + today +")"
j = 1
k = 2
contentAll = ""
for i in range(1,20,2):
# 제목
bookTitle_tag ='#category_layout > tbody > tr:nth-child(' + str(j) + ') > td.goodsTxtInfo > p:nth-child(1) > a:nth-child(1)'
bookTitles = soup.select(bookTitle_tag)
bookTitle = bookTitles[0].text
# 저자/출판사/발행월
auth_tag = '#category_layout > tbody > tr:nth-child(' + str(j) + ') > td.goodsTxtInfo > div'
auths = soup.select(auth_tag)
auth = auths[0].text.replace('\n', ' ').replace('\r', '').replace('\t','').strip()
# 가격/
price_tag ='#category_layout > tbody > tr:nth-child(' + str(j) + ') > td.goodsTxtInfo > p:nth-child(3)'
prices = soup.select(price_tag)
price = prices[0].text.replace('\n', ' ').replace('\r', '').replace('\t', '').strip()
# 요약
summary_tag = '#category_layout > tbody > tr:nth-child(' + str(k) + ') > td:nth-child(2) > p'
summarys = soup.select(summary_tag)
summary = summarys[0].text.replace('\n', ' ').replace('\r', '').replace('\t', '').strip()
# 이미지
bookImg_tag ='#category_layout > tbody > tr:nth-child(' + str(j) + ') > td.image > div > a:nth-child(1) > img'
bookImgs = soup.select(bookImg_tag)
bookImg = bookImgs[0].text.replace('\n', ' ').replace('\r', '').replace('\t', '').strip()
bookImg = (bookImgs[0].attrs['src'].split('/'))[4]
content = '<h3 data-ke-size="size23"><b>' + str(i) + '. ' + bookTitle + '</b></h3>'
content += '<ul style="list-style-type: disc;" data-ke-list-type="disc">'
content += '<li>' + auth + '</li>'
content += '<li>' + price + '</li>'
content += '<li>' + summary + '</li>'
content += '</ul>'
content += '<figure data-ke-type="emoticon" data-ke-align="alignCenter" data-emoticon-isanimation="false"><img src="https://image.yes24.com/goods/' + \
bookImg +'/L" width="300" alt="' + bookTitle + '"/></figure>'
content += '<P>.</P>'
contentAll += content
j = j + 2
k = k + 2
# print( contentAll )
accssToken = tistoryAPI.getAccessToken()
print("Access CODE : " + str(accssToken))
tag_name = "YES24,자기계발,자동포스팅"
tistoryAPI.postWrite('블로그이름기술', t_title, contentAll, visibility=None, category_id='카테고리ID', published=None,
slogan=None, tag=tag_name, acceptComment=None, password=None, output_type="json")
print("글 등록 완료")
자동 발행 포스팅은 테스트 블로그에 게시했다. 전자책으로 출시하여 1일 1포스팅 자동화를 통한 머니 파이프라인 구축방안에 대해 정리했다. 잠자는 동안 돈을 벌고 싶다면 자동화를 해보자.
~~~ 크롤링 자동 발행 결과 ~~~
'월급외 수익 > 구글 애드센스' 카테고리의 다른 글
티스토리 애드센스 자동 광고 설정하기 (2) | 2022.10.03 |
---|---|
구글 애드센스 광고가 안 나올때 해결 방법은? (0) | 2022.09.16 |
알아두면 유용한 구글 애드센스 돈벌기 기초 : 광고의 종류 (0) | 2022.09.10 |
구글애드센스 광고 수익 지급받다 - 파이프라인/패시브인컴 (0) | 2021.12.24 |
구글 애드 센스 - 외국어(영어) 광고 제거하는 꿀팁! (2) | 2021.12.14 |