1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

python google 翻訳seleniumを使って英訳を得る(備忘録)

Posted at

Google翻訳するには、様々な方法があります。
このリンクを参考にしてど自動翻訳してみました。


from bs4 import BeautifulSoup
from selenium import webdriver
import urllib.parse

driver = webdriver.Chrome(r"C:\Users\xxxxxxxx\xxxxx\study\chromedriver.exe")
text = "本日は晴れ。"
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()

It is sunny today.と訳されました。It's fine today.が正しいと思いますが、一応通じます。

1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?