python_note
  • Introduction
  • My Python
    • Anaconda
    • argparse
    • datetime
    • json
    • logging
    • numpy
    • open
    • openCC
    • pandas & csv
    • Socket & SocketServer
    • re
    • yaml
    • smtp
    • 物件操作
    • unittest
    • 線程
    • prettytable
    • IO
    • pycurl
    • sys
    • pickle
    • auto-python-to-exe
    • cython
    • nuitka
  • Crawler
    • Urllib & Requests
      • User-agent
      • Percent-Encoding
      • mail code
    • Selenium
    • TCP & UDP
    • 控制字符(control character)
  • Web Development
    • Flask
      • RESTful api
      • Template
      • blueprint
    • Django
      • 環境佈署(windows)
    • 檢查Port
    • Apache
    • 使用者行為
    • jQuery
    • 壓力測試
    • DataTable
    • Bootstrap
    • CSS
    • JavaScript
    • Chart.js
  • Deep Learning
    • Keras 設定
    • RNN
    • LSTM
  • Test
    • T-Test
  • 資料結構
    • Hash
    • 時間複雜度
  • NLP
    • N-gram
    • CKIP
    • 中文轉數字
    • CRF
    • Mutual Information
    • 模糊比對
  • Linebot
    • Heroku
    • 圖文選單
    • channel
  • Linux
    • 常用指令
    • shell script
    • sshfs
    • ssh
    • nodejs & npm
    • debug
  • GCP
    • app engine
    • ssh(gcp)
    • gsutil
    • brabrabra
    • Load Balancer
    • k8s
  • Database
    • mysql
    • elasticsearch
      • Query
      • Backup and Restore
      • elasticdump
      • es2csv
      • ELK
    • mongodb
      • install
      • authentication
      • pymongo
    • sql server
  • go
    • Swarm
  • Docker
    • Kitematic
    • Dockerfile
    • Swarm
  • Git
  • 其他
    • USB軟體保護
    • Windows效能監視器
  • Blockchain
Powered by GitBook
On this page

Was this helpful?

  1. Crawler
  2. Urllib & Requests

Percent-Encoding

PreviousUser-agentNextmail code

Last updated 5 years ago

Was this helpful?

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

ex.

':' ---> %3A

'/' ---> %2F

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

ex.

原始網址列 ->

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

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

#python3
import urllib.parse

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

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

# 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