Posted By

whitetiger on 11/09/06


Tagged

get http file html post python style String text apache upload web thumbnail PIL font color series60 translate pys60 client available


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

anayhk


Python - Query BabelFish


 / Published in: Python
 

  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  

You need to login to post a comment.