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)
Guest UserPosted Mar 4, 2023, 7:58 PM
Hi Tuhin
Have a look at the code that is now inserted its the same i posted today and im stil experiencing the same issue. Please test this code again on your side and share the compiled output. I might be doing something wrong here.
// latest code with URL link included but still experience same result no change at all.
Tuhin PaulPosted Mar 4, 2023, 3:30 PM
Yes, I think the error is because you are passing an empty string as an argument to the get_attribute method. To fix this, you need to pass the attribute name as the argument. In this case, it should be href. Try the code below:
Make sure to replace the url variable with the actual URL of the page you want to scrape.
Guest UserPosted Mar 4, 2023, 9:28 AM
Hi Tuhin
Do you mind sharing your output here as a solution, because what you mentioned now here tried and this compiles this screen code below. I have all the necessary libraries used from the program but i kept getting this exception all the time. What is best option to fix this problem...?
Tuhin PaulPosted Mar 3, 2023, 11:06 PM
Hello,
See the updated code snippet,I have modified it and it should translate the course titles correctly:
This should create a new column in the DataFrame called Title (hin) that contains the Hindi translation of the course titles.