URL Encoder / Decoder
URLやクエリパラメータのエンコード・デコード。
URLエンコーダー/デコーダーは、特殊文字をURL内で安全に使えるパーセントエンコード形式に変換したり、パーセントエンコードされた文字列を人間が読めるテキストに戻したりするツールです。スペース、&、=、#などの特殊文字はURLで特別な意味を持つため、正しく送信するにはエンコードが必要です。
URLやクエリパラメータの値をエンコーダーに貼り付けると、各unsafe文字が%と2桁の16進コードに置き換えられます。デコーダーは逆の処理を行い、%20をスペースに、%26を&に変換します。
APIリクエスト用クエリ文字列の作成、Webhookペイロードのデバッグ、エンコードされていない特殊文字を含む壊れたリンクの修正などに役立ちます。すべての処理はブラウザ内で行われます。
よくある質問
コード実装
from urllib.parse import quote, unquote, quote_plus, urlencode, urlparse
# Encode a single value (for use in path or query value)
raw = "hello world & more/stuff"
encoded = quote(raw)
print(encoded) # hello%20world%20%26%20more%2Fstuff
# query-string style: spaces become +, / is also encoded
qs_encoded = quote_plus(raw)
print(qs_encoded) # hello+world+%26+more%2Fstuff
# Decode
decoded = unquote(encoded)
print(decoded) # hello world & more/stuff
# Encode a full query string from a dict
params = {"name": "Alice Smith", "city": "São Paulo", "q": "a+b=c&d"}
query = urlencode(params)
print(query) # name=Alice+Smith&city=S%C3%A3o+Paulo&q=a%2Bb%3Dc%26d
# Parse a URL and re-encode its components
url = "https://example.com/search?q=hello world&lang=en"
parsed = urlparse(url)
print(parsed.query) # q=hello world&lang=en (raw)Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.