Whoring out Goo.gl Links

S M W

New member
May 13, 2009
445
2
0
Anyone know how to make a whole bunch of goo.gl links? I have urls in a file and want to convert to goo.gl but don't want to enter every one manually.

I also don't want to be logged in and using API when creating them. Is this possible with PHP? Ajax?
 


Code:
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
That's python. Don't PM me if it breaks ;)

EDIT: inb4 uplinked "you shudda used json module" and dchuk "you should have used xpath"