DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Python - Query BabelFish

  • submit to reddit
        //Example di POST HTTP


import urllib

def translate(lang='it_en', text='ciao'):
	'''Converte delle frasi da una lingua sorgente ad una lingua destinazione'''

	url = urllib.URLopener()
	query = urllib.urlencode({'doit':'done', 'intl':'1', 'lp':lang, 'tt':'urltext', 'urltext':text})
	responde ='', query).read()

	start = responde.find('<div style=padding:10px;>') + 25
	stop = responde.find('</div>', start)

	print responde[start:stop]