Unlock the world of efficient and convenient URL management with Python as we dive into building a URL shortener. In this project, you’ll learn how to create a Python script that transforms long, unwieldy URLs into concise, easy-to-share links.
Whether you’re a web developer, a marketer, or simply someone looking to simplify and track your URL usage, this step-by-step guide will help you create your own URL shortener. Join us as we explore the power of Python in making the internet a more user-friendly place, one link at a time!
import requests
import json
UI = input("Enter the long link: ")
api_key = 'You api key here'
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json',
}
data = {"long_url": UI}
for i in range(3):
result = requests.post("https://api-ssl.bitly.com/v4/shorten", headers=headers, data=json.dumps(data))
if result.status_code == 200:
break
if result.status_code == 200:
link = json.loads(result.content)['link']
print(f"\nYour shortened link: {link}")
else:
print("error occured")
Latest posts by Publisher (see all)
- Age calculator using Javascript, HTML & CSS - October 28, 2023
- Navigation bar using HTML & CSS - October 26, 2023
- Calculator using HTML, CSS & JS - October 26, 2023