I thought I should use Google's translation API when I want to translate English sentences into Japanese with python, but it was charged (´ ・ ω ・ `) Then I thought that I should scrape and get the translation result! So I made it
Python 3.4.3 :: Anaconda 2.3.0 (x86_64)
from selenium import webdriver
from bs4 import BeautifulSoup
import urllib.parse
english = 'As an app designer, you have the opportunity to deliver an extraordinary product that rises to the top of the App Store charts.'
url_text = "https://translate.google.co.jp/#en/ja/{0}".format(english)
url = urllib.parse.quote_plus(url_text, "/:?=&#")
driver = webdriver.PhantomJS()
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html,'html.parser')
print('English')
print(english)
print('Japanese')
print(soup.find(id='result_box').text)
When you want to convert from English to Japanese
I think you can do it by replacing ʻen and
jaof
" https://translate.google.co.jp/#en/ja/{0} ".format (engish) of ʻurl_text
.
Other languages as well
It just stores the string specified by ʻenlish in ʻurl_text
and converts spaces and double-byte characters to the format of ʻURL.
Slow because I have to draw with PhantomJS Cannot be converted if the structure of the web page changes
Well ... If you complain like this, you can use the paid API.
Recommended Posts