“This is the 27th day of my participation in the November Gwen Challenge. See details of the event: The Last Gwen Challenge 2021”.
preface
In our daily work and life, we usually encounter some very long hyperlinks. When you want to forward or record the links, the links are very long and it is not convenient to operate, and the short link services provided by domestic cloud manufacturers are charged. What can we do if we are already living in poverty? It is recommended that you use PyShorteners, two lines of code that shorten long links to create your own short links.
About pyshorteners
It is a popular third party library for Python that makes it easy and quick to produce simple short links to make your work life better.
practice
The installation
pip install pyshorteners
Copy the code
An example to get started
From PyShorteners import Shortener # instantiate short link engine short_engine = Shortener() # use tinyURL to shorten res = short_engine.tinyurl.short('https://phygerr.github.io/httpx-%E4%BC%98%E7%A7%80%E7%9A%84http%E5%AE%A2%E6%88%B7%E7%AB%AF/' ) print(res)Copy the code
Code run result
Short link test
The browser opens the short link and tests whether it can be redirected properly.
Jump is successful
Short chain list
The shortening function of TinyURL can be used directly, but some short links, such as po.st, need to be registered and used with the APIkey.
Pyshorteners supports the following types of short chains:
Break the chain | Whether Key is required |
---|---|
Adf.ly | True |
Bit.ly | True |
Cutt.ly | True |
Git.io | True |
Po.st | True |
Short.cm | True |
Tiny.cc | True |
TinyURL.com | False |
Qps.ru | False |
Ow.ly | False |
Os.db | False |
NullPointer | False |
Is.gd | False |
Da.gd | False |
Clck.ru | False |
Chilp.it | False |
Shorten a few more
From Pyshorteners import Shortener # instantiate short_engine = Shortener() Shorten res1 = = 'https://phygerr.github.io/httpx-%E4%BC%98%E7%A7%80%E7%9A%84http%E5%AE%A2%E6%88%B7%E7%AB%AF/' base_url # short_engine.tinyurl.short(base_url) res2 = short_engine.osdb.short(base_url) res3 = short_engine.isgd.short(base_url) res4 = short_engine.dagd.short(base_url) res5 = short_engine.qpsru.short(base_url) print(res1+'\n',res2+'\n',res3+'\n',res4+'\n',res5+'\n')Copy the code
Code run result
By comparison, you can see that the isGD and DAGD short chains are relatively concise.
5 NullPointer alone
I singled it out because NullPointer supports custom fields. Currently nullPointer supports both fields 0x0.st and ttm.sh. The user can define the shortening engine when instantiating it. The default is 0x0.st.
The default
From Pyshorteners import Shortener # instantiate short_engine = Shortener() base_url='https://phygerr.github.io/httpx-%E4%BC%98%E7%A7%80%E7%9A%84http%E5%AE%A2%E6%88%B7%E7%AB%AF/' # NullPointer,default domain is https://0x0.st res = short_engine.nullpointer.short(base_url) print(res)Copy the code
Code run result
The specified
Short_engine = Shortener(domain='https://ttm.sh') base_url='https://phygerr.github.io/httpx-%E4%BC%98%E7%A7%80%E7%9A%84http%E5%AE%A2%E6%88%B7%E7%AB%AF/' # NullPointer,default domain is https://0x0.st res = short_engine.nullpointer.short(base_url) print(res)Copy the code
Code run result
As you will see, NullPointer generates very good short links.
That’s all for today, thank you for reading, and we’ll see you next time.