Skip to content

Instantly share code, notes, and snippets.

@scionoftech
Created January 1, 2020 13:54
Show Gist options
  • Save scionoftech/93b6a348b5fa7ebd97c5a9985719fd8f to your computer and use it in GitHub Desktop.
Save scionoftech/93b6a348b5fa7ebd97c5a9985719fd8f to your computer and use it in GitHub Desktop.
Google translator using Selenium
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
import time
try:
language_code = "te"
chrome_options = Options()
#chrome_options.add_argument("--disable-extensions")
#chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(executable_path="./chromedriver",options=chrome_options)
driver.get('https://translate.google.com/#view=home&op=translate&sl=en&tl='+language_code)
driver.find_element_by_id("source").clear()
time.sleep(3)
driver.find_element_by_id("source").send_keys("how are you")
time.sleep(3)
output = driver.find_element_by_xpath("//span[@class='tlid-translation translation']//span").text
print(output)
driver.quit()
except NoSuchElementException:
print(NoSuchElementException.args)
@therealbush
Copy link

swag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment