Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to call the short URL interface

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use Python to call short URL interface". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use Python to call short URL interface".

The API API generates the address Tencent short URL (http://url.cn)

Interface 1: http://www.sinadwz.cn/url/dwz.php?url_long=http://www.baidu.com

Interface 2: http://maiyurl.cn/tengxurl?url_long=http://www.baidu.com

Interface 3: http://www.sina-url.cn/txdwz.php?url_long=http://www.baidu.com

Sina short website (http://t.cn)

Interface 1: http://www.sina-url.cn/xinlang?url_long=http://www.baidu.com

API 2: http://www.qqdwz.cn/urlcn/api? url_long= http://www.baidu.com

Interface 3: http://maiyurl.cn/weibourl?url_long=http://www.baidu.com

Generate online address Tencent short URL (http://url.cn)

Interface 1: http://www.sinadwz.cn

Interface 2: http://maiyurl.cn

Interface 3: http://www.sina-url.cn

Sina short website (http://t.cn)

Interface 1: http://www.sina-url.cn

Interface 2: http://www.qqdwz.cn

Interface 3: http://maiyurl.cn

Note:

When ① calls the api interface, simply replace "http://www.baidu.com"" with a long URL that needs to be shortened.

The ② interface supports the url parameter. When the & symbol appears in the url, use% 26 instead (or use the url encoding format), otherwise the parameter may be lost.

③ must start with http (s): / / when filling in url, otherwise the resulting short URL may not be able to access the original website.

④ mentioned above several url.cn short URL api interface, after testing is relatively stable, feel good to remember to collect, so as not to lose.

Frequently asked questions:

① long link conversion, why is the parameter at the end lost?

Answer: because url contains special characters, you need to use UTF8 encoding format to encode url

The ② interface does not return a result. What happens?

A: sometimes there is a delay in the return of data from the API. If the delay is not returned, it will indicate that the generation failed, or because the original link is blocked.

Short URL interface document

PHP call code:

$url = 'http://www.baidu.com';$api_url =' .urlencode ($url); $short_url = file_get_contents ($api_url); echo $short_url

JAVA call code:

Public static void main (String path []) throws Exception {URL u = new URL ("http%3A%2F%2Fwww.baidu.com"); InputStream in = u.openStream (); ByteArrayOutputStream out = new ByteArrayOutputStream (); try {byte buf [] = new byte [1024]; int read = 0; while ((read = in .read (buf)) > 0) {out.write (buf, 0, read) }} finally {if (in! = null) {in. Close ();}} byte b [] = out.toByteArray (); System.out.println (new String (b, "utf-8"));}

Python call code:

Import urllib, urllib2, sys host =''path =' 'method =' GET' querys = 'http%3A%2F%2Fwww.baidu.com' bodys = {} url = host + path +'?'+ querys request = urllib2.Request (url) response = urllib2.urlopen (request) content = response.read () if (content): print (content) Thank you for reading. This is the content of "how to use Python to call short URL Interface". After the study of this article, I believe you have a deeper understanding of how to use Python to call the short URL interface, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report