URL Encoder / Decoder
URL과 쿼리 파라미터를 인코딩하고 디코딩.
URL 인코더/디코더는 특수 문자를 URL에서 사용 가능한 퍼센트 인코딩 형태로 변환하거나, 퍼센트 인코딩된 문자열을 사람이 읽을 수 있는 텍스트로 되돌리는 도구입니다. 공백, &, =, # 같은 특수 문자는 URL에서 특별한 의미를 가지므로 올바르게 전송하려면 인코딩이 필요합니다.
URL이나 쿼리 파라미터 값을 인코더에 붙여넣으면 각 안전하지 않은 문자가 %와 두 자리 16진수 코드로 교체됩니다. 디코더는 반대로 %20을 공백으로, %26을 &로 변환합니다.
API 요청용 쿼리 문자열 구성, 웹훅 페이로드 디버깅, 인코딩되지 않은 특수 문자가 포함된 깨진 링크 수정 등에 유용합니다. 모든 처리는 브라우저에서만 이루어집니다.
자주 묻는 질문
코드 구현
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.