import urllib2
import re
urls = ['http://www.reddit.com/','http://www.twitter.com/']
page = urllib2.urlopen('http://goo.gl/?authed=1').read()
security_token = re.compile('name="security_token" id="security_token" type="hidden" value="(.+?)"').findall(page)[0]
for url in urls:
post = 'url=%s&security_token=%s' % (url,security_token)
response = urllib2.urlopen(urllib2.Request('http://goo.gl/api/shorten', post)).read()
print re.compile('"short_url":"(.+?)"').findall(response)[0], url