Created
January 1, 2020 13:54
-
-
Save scionoftech/93b6a348b5fa7ebd97c5a9985719fd8f to your computer and use it in GitHub Desktop.
Google translator using Selenium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
swag