I'm trying to do translate a web page automatically with a shell script. Here is the interesting part:

wget http://www.google.com/translate?langpair=en%7Ces&u=http%3A%2F%2Fasdf.com

I'm getting the "ERROR 403: Forbidden" even though I can get the translation when using this URL in browser. Could someone explain what's going on? Why google forbids the "translator" usage from shell script? Do they monitor user agent or they have another way to tell if you are a browser or not?

If someone knows another way to do it (for example if there is a console non-interactive browser that would fetch that URL or, perhaps there is another online translation tool I'm not aware of) please let me know.

  • There is a reason they block specific user-agents. In the case of wget it is probably to make it clear they don't want to you do large batch translations of sites. If you try to send a lot of requests to google translate they are likely to give you a captcha or ban your ip. – pehrs May 3 '11 at 23:07

Yes, they check the user agent. Add the -U option to wget, like this:

wget -U "Mozilla/5.0" 'http://www.google.com/translate?langpair=en%7Ces&u=http%3A%2F%2Fasdf.com'

I tested on my machine and I was able to get the page.

Update: Make sure you put quotes around the url (I used single quotes), because the & separator backgrounds everything before it, and the rest gets interpreted as a separate command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.