> For the complete documentation index, see [llms.txt](https://stb11816.gitbook.io/python_note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stb11816.gitbook.io/python_note/crawler/url/bai-fen-bi-bian-ma.md).

# Percent-Encoding

在URL規範中無法直接使用特定符號，必須將其以%加上16進位數值表示

ex.

':' ---> %3A

'/' ---> %2F

若網站的GET請求中包含中文或特定符號，雖然在網址列中看起來一切正常，但把網址貼上TXT或IDE時內容則皆為百分比編碼

ex.

原始網址列 -> ![](https://1401931475-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5_fLw1npOrdnoDM8hP%2F-M5_fNeGxLrPvNyOXvmT%2F-M5_fT1gdkDArrY8PRed%2Ftt.JPG?generation=1587622593274498\&alt=media)

```
貼上編輯器 -> https://tw.buy.yahoo.com/gdsale/SONY-Xperia-XA1-3G-32G-5%E5%90%8B-7100428.html
```

"吋"會以"%E5%90%8B"來表示

```python
#python3
import urllib.parse

print(urllib.parse.quote("吋")) #結果：%E5%90%8B

print(urllib.parse.unquote("%E5%90%8B")) #結果：吋
```

[參考來源](https://openhome.cc/Gossip/Encoding/URLEncoding.html)

```python
# python2
urllib.quote(u'中文測試'.encode('utf-8'))
```

參考來源：\
<https://www.ewdna.com/2012/05/pythonurl-encode-decode.html>\
<https://blog.csdn.net/haoni123321/article/details/15814111>
