Issue
I'm making simple script that will translate words from English to Russian language using requests and BeatifulSoup, the problem is that the result box is empty where should be translated word/ I'm not sure if i should use GET or POST method. This is what I've tried
with open('File.csv', 'r') as file:
csv_reader = csv.reader(file)
for line in csv_reader:
if line[1] == '':
url = 'https://translate.google.com/#en/ru/{}'.format(line[0])
r = requests.get(url, timeout=5)
soup = BeautifulSoup(r.content, 'html.parser')
translate = soup.find('span', id='result_box')
for word in translate:
print(word.find('span', class_=''))
Solution
You might want to consider using the googletrans package.
from googletrans import Translator
translator = Translator()
text = translator.translate('text', src='en', dest='ru')
print(text.text)
Answered By - tbienias
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.