Página 1 de 1

Acortador url python

Publicado: 15 Ene 2016, 20:28
por crack81
un simple acortador url usando el servicio de tinyurl , basicamente la funcion hace un get sobre el sitio wbe de tinyurl y nos regresa una url acortada
import requests

'''
  parameters: website: string that contains a website 
  
  return: return a string with the website encoding 
  
  dependences: module requests
'''
def getShortUrl(website):
    shortUrl=requests.get("http://tinyurl.com/api-create.php?url="+website);
    return shortUrl.content.decode("utf-8")



print("Ejemplo de como acortar un url")
website="https://www.google.com.mx/"
url=getShortUrl(website)
print("la url acortada es ",url)