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

What is the actual operation procedure of Python Chinese conversion url coding

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces to you what is the actual operation step of Python Chinese conversion url coding, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Url coding has a very powerful function, as well as a very simple application skills, so if you convert url coding in Python, do you know anything about it? The following is an introduction to the relevant content of the article. I hope you will get something from browsing the following articles.

Today, modify a weather forecast, but the input city can not get the weather forecast, it feels like the code is wrong, because when you enter a city (such as' Hangzhou'), the address code of url is'% E4% B8% BD% E6% B1% 9F, so you need to make a conversion. Here we use the module urllib.

> import urllib > data = 'Hangzhou' > print data

Hangzhou

> data'\ xe6\ x9d\ xad\ xe5\ xb7\ x9e' > urllib.quote (data)'% E6% 9D% AD% E5% B7% 9e'

What if we want to turn back?

> urllib.unquote ('% E6% 9D% AD% E5% B7% 9E')'\ xe6\ x9d\ xad\ xe5\ xb7\ x9e' > > print urllib.unquote ('% E6% 9D% AD% E5% B7% 9e')

Careful students in Hangzhou will find that% C0%F6%BD%AD appears in Tieba url instead of'% E4% B8% BD% E6% B1% 9F, which is actually a coding problem. Baidu is gbk, and other general websites such as google are utf8. So it can be implemented with the following statements.

> import sys,urllib

> s = 'Hangzhou'

> > urllib.quote (s.decode (sys.stdin.encoding)

.encode ('gbk'))

% BA%BC%D6%DD

> > urllib.quote (s.decode (sys.stdin.encoding)

.encode ('utf8'))

'% E6% 9D% AD% E5% B7% 9e'

On the Python Chinese conversion url coding what is the actual steps to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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