标签:enum string html query aci base coff tps nbsp
1from urllib.parse import urlparse, urlunparse, urlsplit, urlunsplit, urljoin, urlencode, parse_qs, parse_qsl, quote,unquote
1result = urlparse(‘https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_9094304700265862330%22%7D&n_type=0&p_from=1‘)
2print(type(result), result)
3print(result.scheme)
4print(result[0])
1data = [‘https‘, ‘www.baidu.com‘, ‘index.html‘, ‘user‘, ‘a=6‘, ‘comment‘]
2print(urlunparse(data))
1result = urlsplit(‘https://www.baidu.com/index.html;user?a=6#comment‘)
2print(result)
3print(result.scheme)
4print(result[0])
1data = [‘https‘, ‘www.baidu.com‘, ‘index.html‘, ‘a=6‘, ‘comment‘]
2print(urlunsplit(data))
1print(urljoin("https://www.baidu.com/", ‘FAQ.html‘))
2print(urljoin(‘http://www.baiduu.com‘, ‘https://www.gxj.com/FAQ.html‘))
1params = {
2 ‘name‘: ‘germey‘,
3 ‘age‘: 22
4}
5baseurl = ‘http://www.baiduu.com?‘
6url = baseurl + urlencode(params)
7print(‘--urlencode--%s‘ %url)
1query = ‘name=germey&age=22‘
2print(‘--parse_qs---%s‘ %parse_qs(query))
1query = ‘name=germey&age=22‘
2print(‘--parse_qsl--%s‘ %parse_qsl(query))
1keyword = ‘我爱你‘
2url = ‘http://www.baiduu.com‘ + quote(keyword)
3print(‘--quote()--%s‘%url)
1keyword =‘%E6%88%91%E7%88%B1%E4%BD%A0‘
2url = ‘http://www.baiduu.com‘ + unquote(keyword)
3print(‘--quote()--%s‘%url)
标签:enum string html query aci base coff tps nbsp
原文地址:https://www.cnblogs.com/gxj521test/p/10206545.html