파이썬 뷰티플 수프 이용한 네이버 블로그 자동등록 방법

조회수 776회

제가 파이썬을 이용한 네이버 자동 업로드 툴을 만들고 있는데요, 아래소스를 이용해서 쇼핑몰의 상품명과 상세설명, 이미지주소와 제품링크를 긁어오게 해놓았습니다.

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)

여기서 긁어 온 정보를, 아래 네이버 블로그에 업로드하는 소스 하단 타이틀은 타이틀에, 컨텐츠는 본문에 자동으로 넣어 등록되게끔 하고 싶습니다.

import xmlrpc.client
from urllib.request import urlopen
from bs4 import BeautifulSoup

API_URL = 'https://api.blog.naver.com/xmlrpc'


class NaverBlog(object):
    def __init__(self, user_id, api_key):
        self.__server = None
        self.__user_id = user_id
        self.__api_key = api_key
        self.__categories = []

        try:
            self.__set_categories()
        except Exception as e:
            raise e

    def __client(self):
        if self.__server is None:
            self.__server = xmlrpc.client.ServerProxy(API_URL)

        return self.__server

    def __set_categories(self):
        categories = self.__client().metaWeblog.getCategories(self.__user_id,
                                                              self.__user_id,
                                                              self.__api_key)

        for category in categories:
            self.__categories.append(category['title'])

    def post(self, title, description, category, publish=True):
        struct = {}
        struct['title'] = title
        struct['description'] = description
        if category in self.__categories:
            struct['categories'] = [category]

        try:
            return self.__client().metaWeblog.newPost(self.__user_id,
                                                      self.__user_id,
                                                      self.__api_key,
                                                      struct,
                                                      publish)
        except Exception as e:
            raise e


def main():
    naver = NaverBlog('아이디', 'API비밀번호')

    naver.post('타이틀', '본문','카테고리 한글')

if __name__ == '__main__':
    main()

상품정보 수집과 등록을 아래 네이버 블로그 자동 등록 소스 하나로 활용해 등록하게 하려면 이 두 소스를 어떻게 합치면 구현할 수 있을까요? 글이 지저분하게 등록되어 여러차례 수정하였지만 잘 되지 않네요.조언 부탁드립니다

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)