Short Link Generation - How to Process 100 Long Links Offline
As long as you do social media, you'll notice that on other people's FB, on ins, it's all short links. Very easy for users to click and spread. You will also be able to easily find similar online short link generation tools online to help you make short links. But the disadvantages are also obvious:1, unable to batch.;2, the domain name cannot be attributed to yourself. I made a little plugin above so you can experience it.
Short Chain Generation Market
I checked some information, found that the short link is also a very interesting tool market, and the current overseas leader, is bitly. to convert long URL to short links, you can use some free short link services, of course, the following is just a list of overseas business services, domestic services can be Google and Baidu under.

Here are a few commonly used tools:
- Bitly: A very popular short link service with support for customized links and the ability for registered users to view link click data.Visit Bitly
- TinyURL: Create short links without registration and support customizing parts of short links.Access to TinyURL
- Rebrandly: Provides short links to customized domains, suitable for branded use, with limited functionality in the free version.Visit Rebrandly
- Google Shortlink Generator: Although Google's official URL short linking service has moved to Firebase Dynamic Links, you can create short links if you have a Firebase project.Access to Firebase
- Ow.ly: Hootsuite offers a short link service suitable for social media management and tracking link clicks.Visit Ow.ly
- Shortlink Generator Plugin: Some browser plug-ins such as "Short URL" can help you to quickly generate short links in your browser.
These tools offer simple interfaces, just paste in the long link and click generate to get the short link.
Bitly API Paid Bulk Short Link Generation
Using the Bitly API, I'm going to use Python for the example here. First, register and get a Bitly API Access TokenThen, install the requests library (if you don't have it already). Then, install the requests library (if not already installed):
pip install requests
Next, write the Python code:
import requests
def shorten_url(long_url).
# Your Bitly Access Token.
access_token = "YOUR_BITLY_ACCESS_TOKEN"
headers = {
"Authorization": f "Bearer {access_token}",
"Content-Type": "application/json"
}
payload = {
"long_url": long_url
}
response = requests.post("https://api-ssl.bitly.com/v4/shorten", json=payload, headers=headers)
if response.status_code == 200:: If response.status_code == 200.
return response.json().get("link")
else.
print("Error:", response.status_code, response.text)
return None
# Example Usage
long_url = "https://www.yourwebsite.com/some/very/long/url"
short_url = shorten_url(long_url)
print("Short URL:", short_url)
commander-in-chief (military) "YOUR_BITLY_ACCESS_TOKEN"
Replace it with the Access Token you got at Bitly. after running theshort_url
will be the short link generated.
Free Bulk Short Link Generation with Pyshortener
pyshorteners
is a simplified Python library that automatically handles short link generation and supports multiple short link services. The installation method is as follows:
pip install pyshorteners
Then use the following code:
import pyshorteners
def shorten_url(long_url).
s = pyshorteners.Shortener()
short_url = s.tinyurl.short(long_url)
return short_url
# Example Usage
long_url = "https://www.yourwebsite.com/some/very/long/url"
short_url = shorten_url(long_url)
print("Short URL:", short_url)
Bitly VS Pyshortener
Pros and cons of using the Bitly API
Pros:
- Data tracking: Bitly provides statistics on link clicks and can track user click behavior (e.g., geographic location, device type, etc.), which is useful for analyzing user behavior.
- Brand Customization: Bitly allows the use of custom domains in the premium version to set up short links as branded links with a more professional feel.
- Stability and reliability: Bitly is an old school short link service with high short link stability and low likelihood of service interruption.
Drawbacks:
- API Access Token: The need to register and obtain an API access key adds a configuration step.
- Free version limitations: The free version has quantity limitations (e.g., the number of free shortlinks generated per month), which is suitable for personal use, but if you need to generate a large number of shortlinks, Bitly costs more.
- Relying on API requests: Generating short chains depends on API requests, if used frequently you need to control the number of API calls to avoid exceeding the rate limit.
Applicable Scenarios::
- Ideal for users who need to customize their brand and track the effectiveness of short links, especially in scenarios where there is more social media promotion and click data needs to be analyzed.
Advantages and disadvantages of using the pyshorteners library
Pros:
- simple and fast: No need to register an account or get a key, just install the library and use it, suitable for creating shortlinks quickly.
- Free and unlimited: The free version of TinyURL has no generation quantity limit and is very friendly for personal or small-scale use scenarios.
- Support for multiple short link services::
pyshorteners
Supports different shortlink providers (e.g. Is.gd, Bitly, etc.) for flexible selection.
Drawbacks:
- Lack of data tracking: The generated links do not have data analytics to view clicks or user behavior.
- Poor branding: TinyURL domains are used by default, there is no branding customization feature, and short links are more suitable for ad-hoc use.
- Differences in service stability: TinyURL, as a veteran free service provider, has fair stability, but the free service short link service providers may have frequent service interruptions or maintenance.
Applicable Scenarios::
- Ideal for small personal projects, scenarios where click-through data does not need to be tracked, such as temporary sharing links, simplified links for personal use, etc.
summarize and compare
methodologies | Data tracking | branding | utilization threshold | stability | Applicable Scenarios |
---|---|---|---|---|---|
Bitly API | be | be in favor of | high | your (honorific) | Enterprise-level, click-through-analytics-required data |
pyshorteners (TinyURL) | clogged | unsupported | relatively low | high | Personal use, temporary short links |
testimonials::
- If professional data tracking and branded short links are required: Use Bitly.
- If you only need to generate shortcut links, without the need for statistics and branding, and with a focus on convenience: use the
pyshorteners
The
How to use EXCEL to batch generate short links
Batch operation, can not be separated from the need for excel help, I wrote another code, you can put the long chain in the first column of excel, short chain in the third column, or the second column, how to adjust the specific look at you, my code is put in the third column, because I put the ID in the second column.
You can use the pandas
library to read and write Excel files while using the pyshorteners
The library generates short links.
Here is the complete code:
Front Mount
Please make sure that you have installed the pandas
cap (a poem) pyshorteners
Coop:
pip install pandas pyshorteners openpyxl
code example
Suppose you have an Excel file called urls.xlsx
, the first column (i.e. column A) holds the long links and you want to hold the short links in the third column (i.e. column C). Here is the code:
import pandas as pd
import pyshorteners
def shorten_urls_in_excel(file_path).
# Reading Excel files
df = pd.read_excel(file_path)
# Initialize Short Link Generator
shortener = pyshorteners.Shortener()
# Iterate through the first column and write the generated short link to the third column
df['Shortened URL'] = df.iloc[:, 0].apply(lambda x: shortener.tinyurl.short(x) if pd.notnull(x) else None)
# Write updated DataFrame back to Excel
df.to_excel(file_path, index=False)
# Usage Example
file_path = 'urls.xlsx'
shorten_urls_in_excel(file_path)
Code Description
- Read the Excel file and store the data in the
DataFrame
Center. - utilization
apply()
method traverses the first column, generates a short link for each URL and stores it in a new column"Shortened URL"
(i.e., the third column). - Place the modified
DataFrame
Save back to the original Excel file.
Thus, after running the code, the third column of the Excel file will contain the short link to the corresponding URL.
Is there a statute of limitations for short links generated offline?
There are. This depends on the API setup, and if the business is in it for the long term, it is still recommended to use a paid API to get the information and maintain the short links.
Any recommendations for short link generation online?
It's all pretty much the same. Domesticwebmaster's homeThere it is.