over 4 years ago
How can I send, from within a Python script, a word to translation site and fetch the results?
about 4 years ago
I didn't understand what do you mean by sending a word to translation site. To me, it makes more sense to call an API to translate your text. But if you really want to use some site, it can be a little tricky. On the top of my head, I can think of two approaches.
1. You have to manually inspect the headers and parameters in the actual request which the site of your choice is using to translate the text and then you have to simulate the same request using curl or requests module with your text and source and target languages. Then parse the response returned and extract the translated text from it.
2. You can use any automation library which would open the site in browser instance, fill the text, language pair with your values and simulate the form submit. Once response gets rendered on browser screen, use any HTML parser and extract your translated text from it.
You can use the simplest approach of using some translation web service.
Some good translation services are:
Paid: [Microsoft Translate], [Google Translate], Bing Translate
Free: [transltr], [hablaa]
An example using transltr :
text = 'Test'
source_lang = 'en'
target_lang = 'es'
url = 'http://www.transltr.org/api/translate?text=' + urllib.quote_plus(text) + '&to=' + target_lang + '&from=' + source_lang
response = requests.get(url)
Ofcourse, you need to put checks in this snippet.
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Terms of Service
| © copyright 2021 FindNerd.com. All rights reserved.
Sign up using