Learning immediately: https://edu.csdn.net/course/play/24797/282208?utm_source=blogtoedu
1.urllib.parse: for parsing URL
2. Use the urlparse () function to parse the string
3. Use urlunparse () function can be the object or a tuple ParseResult restored to promote wear URL from
4.parse_qs (), parse_qsl () is used to resolve the query string to get a dictionary or list
5.urlencode (): to restore a list or dictionary into the query string
import urllib.parse as up url = 'https://blog.csdn.net/happyk213' # uv = up.urlparse(url) # print(uv) # print('scheme:', uv.scheme) # print('netloc:', uv.netloc) # print('path:', uv.path) # print('params:', uv.params) # print('query:', uv.query) # print('fragment', uv.fragment) # # uv2 = up.urlunparse(uv) # print(uv2) str = 'name=123&name=abc&age=18&sex=1&age=1&height=190' strf = up.parse_qs(str) print(strf) strf = up.parse_qsl(str) print(strf) strpq = {'name': ['123', 'abc'], 'age': ['18', '1'], 'sex': ['1'], 'height': ['190']} strpql = [('name', '123'), ('name', 'abc'), ('age', '18'), ('Sex ','. 1 '), (' Age ','. 1 '), (' height ',' 190 ')] print (up.quote (' boring day ape ')) # transcoding #解码 print(up.unquote('%E6%97%A0%E8%81%8A%E7%8C%BF%E7%9A%84%E4%B8%80%E6%97%A5')) print(up.urlencode(strpq)) print(up.unquote(up.urlencode(strpq))) print(up.urlencode(strpql))