In [1]:
import urllib.parse
In [2]:
s = '日本語'
In [3]:
s_quote = urllib.parse.quote(s)
In [4]:
print(s_quote)
In [5]:
print(type(s_quote))
In [6]:
b = s.encode()
In [7]:
print(b)
In [8]:
print(type(b))
In [9]:
print(urllib.parse.quote(b))
In [10]:
s_quote_sj = urllib.parse.quote(s, encoding='shift-jis')
In [11]:
print(s_quote_sj)
In [12]:
b_sj_quote = urllib.parse.quote(s.encode('shift-jis'))
In [13]:
print(b_sj_quote)
In [14]:
print(s_quote_sj == b_sj_quote)
In [15]:
print(urllib.parse.quote('http://x-y_z.com'))
In [16]:
print(urllib.parse.quote('http://x-y_z.com', safe=''))
In [17]:
print(urllib.parse.quote('http://x-y_z.com', safe='/:'))
In [18]:
print(urllib.parse.quote('+ /'))
In [19]:
print(urllib.parse.quote_plus('+ /'))
In [20]:
print(urllib.parse.quote_plus('+ /', safe='+/'))
In [21]:
page_title = '日本語'
In [22]:
base_ja = 'https://ja.wikipedia.org/wiki/'
In [23]:
print(base_ja + urllib.parse.quote(page_title))
In [24]:
full_url = 'https://ja.wikipedia.org/wiki/日本語'
In [25]:
print(urllib.parse.quote(full_url, safe=':/'))
In [26]:
print(base_ja + urllib.parse.quote('OK コンピューター'))
In [27]:
print(base_ja + urllib.parse.quote('OK コンピューター'.replace(' ', '_')))
In [28]:
print(s_quote)
In [29]:
print(urllib.parse.unquote(s_quote))
In [30]:
print(s_quote_sj)
In [31]:
print(urllib.parse.unquote(s_quote_sj))
In [32]:
print(urllib.parse.unquote(s_quote_sj, 'shift-jis'))
In [33]:
print(urllib.parse.unquote('a+b'))
In [34]:
print(urllib.parse.unquote_plus('a+b'))
In [35]:
b_unquote = urllib.parse.unquote_to_bytes(s_quote)
In [36]:
print(b_unquote)
In [37]:
print(b_unquote.decode())
In [38]:
b_unquote_sj = urllib.parse.unquote_to_bytes(s_quote_sj)
In [39]:
print(b_unquote_sj)
In [40]:
print(b_unquote_sj.decode('shift-jis'))