Click here to Skip to main content
16,019,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi Team

I want to print text translation and data frame objects, after my pip installation from translate and google i go this error. How do print these objects without having this error?

What I have tried:

Python
<pre>from google_translate import translate
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
from google_trans import Translator
import pandas as pd
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 = "https://www.classcentral.com/collection/top-free-online-courses"
driver.get(url)

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('href')] for course in courses],
                    columns=['Title (eng)', 'Link'])

df['Title (hin)'] = df['Title (eng)'].apply(lambda x: translate(x, dest='hi').text)

print('course.text','Title' )
Posted
Updated 2-Mar-23 9:23am

1 solution

How many arguments print command accepts?
Python
print('course.text','Title' )


Use:
Python
print('{0} and {1}'.format('course.text', 'Title'))


More at: 7. Input and Output — Python 3.11.2 documentation[^] and Your Guide to the Python print() Function – Real Python[^]
 
Share this answer
 
Comments
Gcobani Mkontwana 2-Mar-23 16:30pm    
@Maciej i want to print all objects on the program, i notice its complaining about module line 1 from googletrans as import translate. Had an issue with this object as unreference, then install pip i googletrans, then translate. What am i missing if you replicate this program on your machine, can this be same problem on your side as well?
Maciej Los 2-Mar-23 16:39pm    
Sorry, but i don't want to install google_translate module. So, i can't reproduce your issue.
Gcobani Mkontwana 2-Mar-23 17:02pm    
@Maciej alright but if want to print all objects how do achieve that?
Gcobani Mkontwana 2-Mar-23 17:04pm    
@Maciej this whats get thrown from the IDE : File "C:\Users\Zux\PycharmProjects\ClassCentral\main.py", line 1, in <module>
from google_translate import translate
File "C:\Users\Zux\PycharmProjects\ClassCentral\ClassCentral\Lib\site-packages\google_translate.py", line 119
print translation.encode(encoding)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?"
Richard Deeming 3-Mar-23 3:50am    
So what happened when you read the error message and did what it told you to do?
print(translation.encode(encoding))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900