Hi Team
I have a small issue, the code is fine but the problem is with the module its throwing an error below. What i did was pip install googletrans, because i am using data frame to translate language from English to Hindi. How can i fix this issue?
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(x, dest='hi').text)// Before the error was unference name translate(then install pip install translate, the new error now is because of this first fix.
print('{0} and {1}'.format('course.text', 'Title'))
from google_translate import translate
// pycharm exception from terminal
File \main.py", line 1, in
from google_translate import translate
packages\google_translate.py", line 119
print translation.encode(encoding)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Guest UserPosted Mar 3, 2023, 6:21 AM
Hi Tuhin
I did follow your steps, it works for only for that module. Now it sems i have do them one by one, because it did the same with other libraries as well. Must i follow your first steps will all .... py files and put print....? Have a look at the exception below..
Traceback (most recent call last):
File "C:\Users\Zux\PycharmProjects\NewAssignment\main.py", line 39, in
df['Title (hin)'] = df['Title (eng)'].apply(lambda x: translator.translate(x, dest='hi').text)
File "C:\Users\Zux\anaconda3\envs\NewAssignment\lib\site-packages\pandas\core\series.py", line 4771, in apply
return SeriesApply(self, func, convert_dtype, args, kwargs).apply()
File "C:\Users\Zux\anaconda3\envs\NewAssignment\lib\site-packages\pandas\core\apply.py", line 1123, in apply
return self.apply_standard()
File "C:\Users\Zux\anaconda3\envs\NewAssignment\lib\site-packages\pandas\core\apply.py", line 1174, in apply_standard
mapped = lib.map_infer(
File "pandas\_libs\lib.pyx", line 2924, in pandas._libs.lib.map_infer
File "C:\Users\Zux\PycharmProjects\NewAssignment\main.py", line 39, in
df['Title (hin)'] = df['Title (eng)'].apply(lambda x: translator.translate(x, dest='hi').text)
File "C:\Users\Zux\anaconda3\envs\NewAssignment\lib\site-packages\google_trans\client.py", line 114, in translate
data = self._translate(text, dest, src)
File "C:\Users\Zux\anaconda3\envs\NewAssignment\lib\site-packages\google_trans\client.py", line 55, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\Zux\anaconda3\envs\NewAssignment\lib\site-packages\google_trans\gtoken.py", line 200, in do
self._update()
File "C:\Users\Zux\anaconda3\envs\NewAssignment\lib\site-packages\google_trans\gtoken.py", line 65, in _update
code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'
Tuhin PaulPosted Mar 3, 2023, 12:48 AM
To fix this issue, you can edit the google_translate.py file and add the missing parenthesis in the print statement. It should look like this:
Alternatively, you can use a different translation module instead of google_translate module. Since you have already installed googletrans module, you can use it to translate the text from English to Hindi. Here's how you can modify your code to use googletrans instead of google_translate:
This will fix the issue and translate the text from English to Hindi using the googletrans module.