There are various ways to translate Google. I tried to translate automatically by referring to this link.
from bs4 import BeautifulSoup
from selenium import webdriver
import urllib.parse
driver = webdriver.Chrome(r"C:\Users\xxxxxxxx\xxxxx\study\chromedriver.exe")
text = "It's sunny today."
url_text = "https://translate.google.co.jp/#ja/en/{0}".format(text)
url = urllib.parse.quote_plus(url_text, "/:?=&#")
driver.get(url)
html = driver.page_source
result = BeautifulSoup(html, "html.parser").find(class_="tlid-translation translation").text
print(result)
driver.close()
driver.quit()
Translated as It is sunny today. I think It's fine today. Is correct, but it works.
Recommended Posts