import urllib, httplib
conn = httplib.HTTPConnection('goo.gl')
params = urllib.urlencode({'url':'http://qiye.163.com'})
conn.request('POST', '/api/shorten', headers={"Content-Type":"application/x-www-form-urlencoded"}, body=params)
result = conn.getresponse()
resultContent = result.read()
print resultContent
python 调用google 段网址服务
本文介绍了一个简单的Python脚本,用于通过Google提供的API实现URL缩短功能。该脚本使用了httplib和urllib库来发送HTTP请求,并展示了如何将长链接转换为更短的形式。

被折叠的 条评论
为什么被折叠?



