Google translate is for use with a GET request, not a POST request. However, urrllib2 will automatically send POST if you add any data to your request.
The solution is to build a url asking you to GET .
You will need to change the line request = urllib2.Request('http://www.translate.google.com', urllib.urlencode(data)) your code.
Here:
querystring = urllib.urlencode(data) request = urllib2.Request('http://www.translate.google.com' + '?' + querystring )
And you will get the following result:
<span id="result_box" class="short_text"> <span title="word" onmouseover="this.style.backgroundColor='#ebeff9'" onmouseout="this.style.backgroundColor='#fff'"> parola </span> </span>
By the way, youโre violating Googleโs terms of service; study them if you do more than crack a little script for training.
Using requests
I highly recommend that you stay away from urllib, if possible, and use the excellent requests library, which will allow you to use HTTP effectively with Python.
Thomas Orozco Feb 22 '12 at 23:19 2012-02-22 23:19
source share