Python - Query BabelFish


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import string, urllib
  2.  
  3. def clean(text):
  4. return ' '.join(string.replace(text.strip(), "\n", ' ').split())
  5.  
  6. def translate(frase, da, a):
  7.  
  8. frase = clean(frase)
  9.  
  10. params = urllib.urlencode({'BabelFishFrontPage':'yes','doit':'done','urltext':frase,'lp':da+'_'+a})
  11.  
  12. response = urllib.urlopen('http://babelfish.altavista.com/tr', params)
  13.  
  14. import time
  15. print params
  16. time.sleep(1)
  17.  
  18. f = open("prova.html","w")
  19.  
  20. html = response.read()
  21.  
  22. f.write(html)
  23.  
  24. f.close()
  25.  
  26. print html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.