Gcobani Mkontwana

Gcobani Mkontwana

  • 568
  • 1.9k
  • 406.6k

translating text using data frame from google trans not translating

Mar 3 2023 7:53 PM

hi team

I have a working script  from python, but its not translating my english text into Hindi and used pandas as data frame to count number of courses from the website and does give me list of courses available. But now the problem my translating these courses from English to Hindi is translatexx0000.  I need some help here could be doing something from the data frame in my lamba expression to translate these text into Hindi.

 

// python script

import translate
from google_trans import Translator
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
import pandas as pd
import urllib.request as urllib2
import time

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument("window-size=1920,1080")
driver = webdriver.Chrome(options=chrome_options)
url = "./....classcentral.com/collection/top-free-online-courses"//i cant put url links dont have enough reputation
driver.get(url)

#google translating languages
#translate = Translator()

try:
    while True:
        # wait until button is clickable
        WebDriverWait(driver, 1).until(
                expected_conditions.element_to_be_clickable((By.XPATH, "//button[@data-name='LOAD_MORE']"))
            ).click()
        time.sleep(0.5)
except Exception as e:
    pass

all_courses = driver.find_element(by=By.CLASS_NAME, value='catalog-grid__results')
courses = all_courses.find_elements(by=By.CSS_SELECTOR, value='[class="color-charcoal course-name"]')

df = pd.DataFrame([[course.text, course.get_attribute('')] for course in courses],
                    columns=['Title (eng)', 'Link'])

df['Title (hin)'] = df['Title (eng)'].apply(lambda x: translate.Translator(x, dest='hi'))// problem is here and need some help

print(df)

 


Answers (4)