파파고 translation API는 21년 6월 30일까지 무료 베타 서비스로 제공되었으나 현재는 유료로 바뀌어있다.
약 5천개의 문장을 번역을 해야하는 상황인데, 일회성으로 사용할 것이어서(과금을 하지 않기 위해..) selenium과 크롬 드라이버를 이용해서 번역을 자동화했다.
* NAVER Cloud Papago Translation
https://www.ncloud.com/product/aiService/papagoTranslation
NAVER CLOUD PLATFORM
cloud computing services for corporations, IaaS, PaaS, SaaS, with Global region and Security Technology Certification
www.ncloud.com

약 10만 글자 정도 번역이 필요한 상태이다.
요금이 막 그렇게 비싸지는 않지만, 지속적으로 사용할 것이 아니어서, 크롬 드라이버와 셀레니움을 이용해서 자동화했다.
text 리스트에 번역해야할 문장들을 넣고 모든 문장에 대해 번역을 진행한다.
| 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 29 30 31 32 33 34 35 36 37 38 | import time from selenium import webdriver import csv import pandas as pd from bs4 import BeautifulSoup as bs import os import json text=['안녕하세요.', '내 이름은 대욱이야', '만나서 반가워'] try:     url = "https://papago.naver.com/"     # 시크릿모드로 하기 위함     chrome_options = webdriver.ChromeOptions()     chrome_options.add_argument("--incognito")     chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])     browser = webdriver.Chrome(f'chromedriver.exe', chrome_options=chrome_options)     browser.get(url)     browser.implicitly_wait(2)     input_box = browser.find_element_by_css_selector('textarea#txtSource')     button = browser.find_element_by_css_selector('button#btnTranslate')     x_button = browser.find_element_by_class_name('btn_text_clse___1Bp8a')     # text - 리스트에서 하나씩 번역     for i in text:         print(i)         input_box.clear()         input_box.send_keys(str(i))         # click translate button         button.click()         time.sleep(4)         soup = bs(browser.page_source, 'html.parser')         target_text = browser.find_element_by_css_selector('div#txtTarget').text         print(target_text)         x_button.click()         time.sleep(3)     print('종료') except Exception as msg:     error_msg = "번역기 에러:"+str(msg)     browser.close() | cs | 

크롬이 켜지고 혼자 우르르르ㅡㅡㅡ 번역하고 끝난다.
편하다. (복붙해서 하나씩 번역했더라면... 아직도 하고 있을 듯)
# 추가사항
1/1과 같은 문장은 한국어로 감지가 되지 않는다.
따라서 직접 source 언어와, target 언어를 url에 파라미터로 넣어서 해결해줄 수 있다.
위 코드 11라인에 URL을 "https://papago.naver.com/?sk=ko&tk=en" 로 해주면 된다.
'Python' 카테고리의 다른 글
| [Error] 파이썬 셀레니움 크롬 chrome not reachable 에러 해결 (4) | 2021.12.17 | 
|---|---|
| [Python] Selenium과 Chrome driver를 활용한 Google Translation 자동화 (0) | 2021.12.08 | 
| [Python] 네이버 카페 게시글 크롤러(feat. 크롬 드라이버 & 셀레니움) (6) | 2021.11.23 | 
| [Python] Flask 및 jQuery를 사용하여 AJAX 파일 업로드 (2) | 2021.11.21 | 
| [Python] 괄호 안에 문자 제거하기(정규식) (0) | 2021.11.15 | 
 
										
									 
										
									
댓글