如何用谷歌翻译器翻译单词?

时间:2018-07-14 14:24:09

标签: python beautifulsoup

我正在制作一个简单的脚本,该脚本将使用请求和BeatifulSoup将单词从英语翻译成俄语,问题是结果框为空,应翻译单词/我不确定应该使用GET还是POST方法。这就是我尝试过的

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_=''))

2 个答案:

答案 0 :(得分:4)

您可能要考虑使用googletrans软件包。

toUnstyled

答案 1 :(得分:0)

这个问题是两年前提出的,所以我会在这里发布答案或一个建议。如果符合您的需求,您可能需要尝试deep_translator软件包。

from deep_translator import GoogleTranslator

translated = GoogleTranslator(source='auto', target='ru').translate(text='happy coding')
相关问题