In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the URL encoding decoding example analysis related knowledge, detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that everyone will have a harvest after reading this URL encoding decoding example analysis article, let's take a look at it.
Case thinking
In many cases, the reason for the garbled code is actually caused by the user (developer) himself. If you open a file in the wrong way, garbled characters will appear. For example, text files in UTF-8 format are opened incorrectly using GBK mode. The above example is actually a wrong way to open (or not fully open). In fact, our first instinct when we see the code above is to look up what it is. According to the experience of Xiaobian (no experience can also be Baidu), this should be URL coding, and then Xiaobian found the webmaster tool for testing also determined that the coding method is URL coding.
What is URL coding?
URL encoding is a special form of encoding, named URL encoding because it was originally applied to URLs. We know that Chinese and other non-English characters cannot appear in the URL (it can also be understood that non-ASCII characters cannot appear), but we do need to enter some non-ASCII characters in the URL (we know that GET method parameters are added to the URL, if you cannot enter non-ASCII characters in the URL, it means that GET parameters cannot achieve other text parameters), so there is a URL encoding standard. URLs are encoded by representing non-ASCII characters as % and available ASCII characters, so that non-ASCII characters can be represented by these ASCII characters.
Little friends will say, you see this address bar also appeared Chinese? In fact, this is browser optimization, in order to let you know this link, the browser will decode the URL code in the address bar, so you will see Chinese
How to decode URL encoding
In the front-end development for this data is generally written in JavaScript a decoding program to decode (now there are a lot of ready-made decoding js code segment), small data we can go to the webmaster tool inside decoding (this way is usually used to verify whether it is URL encoding). But we need to decode these URL codes when crawling data, so we have to solve them in python.
Python has its own urllib library, and we know that the request module of this library can make requests, and the parse module can parse html code. In fact, it can also decode URL encoding. The following is an example of decoding code. You can take it as a reference.
import requestsimport urllib.parseurl = "https://www.yisu.com/article"headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'}data = requests.get (url, headers)data = data.textdata =urllib.parse.unquote(data)print(data) The content of this article on "URL encoding decoding example analysis" is introduced here, thank you for reading! I believe everyone has a certain understanding of the knowledge of "URL encoding and decoding example analysis." If you still want to learn more knowledge, please pay attention to the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.