How to Parse a URL — Breaking Down Every Part
URLs are more structured than they appear. Every part of a URL has a name and a specific meaning. Understanding that structure matters when building web applications, debugging routing issues, handling redirects, or manipulating links programmatically.
Parse any URL instantly with our URL Parser tool — see every component broken down clearly.
URL Structure — Every Component Named
Take this URL: https://api.toolchecking.com:8080/v1/results?q=ssl&limit=10#section-2
Breaking it down:
https — Protocol (or scheme). Defines how the client communicates with the server. Others: http, ftp, mailto, ws (WebSocket), file. api — Subdomain. Part of the hostname. toolchecking.com — Domain. Registerable label that identifies the organisation or site. :8080 — Port. Specifies which port the server listens on. HTTPS defaults to 443, HTTP to 80 — these are omitted when using defaults. /v1/results — Path. Hierarchical location of the resource on the server. ?q=ssl&limit=10 — Query string. Key-value pairs separated by & after ?. Used to pass parameters to the server. #section-2 — Fragment (or hash). Processed by the browser only, never sent to the server. Used for in-page navigation or client-side state.
Parsing URLs in Code
JavaScript — URL API
const url = new URL("https://api.toolchecking.com:8080/v1/results?q=ssl&limit=10#section-2");url.protocol // "https:" url.hostname // "api.toolchecking.com" url.port // "8080" url.pathname // "/v1/results" url.search // "?q=ssl&limit=10" url.searchParams.get("q") // "ssl" url.hash // "#section-2"
Python — urllib.parse
from urllib.parse import urlparse, parse_qsparsed = urlparse("https://api.toolchecking.com:8080/v1/results?q=ssl&limit=10") parsed.scheme # "https" parsed.netloc # "api.toolchecking.com:8080" parsed.path # "/v1/results" parsed.query # "q=ssl&limit=10" parse_qs(parsed.query) # {"q": ["ssl"], "limit": ["10"]}
URL Encoding
URLs can only contain a limited set of characters. Special characters must be percent-encoded: a space becomes %20, @ becomes %40, / becomes %2F when used in a query string value.
JavaScript: encodeURIComponent() encodes everything except letters, digits, and - _ . ~ Python: urllib.parse.quote() for encoding, urllib.parse.unquote() for decoding
The difference between encodeURI() and encodeURIComponent(): encodeURI() encodes a full URL and leaves characters like ? # / intact. encodeURIComponent() encodes individual components and encodes those characters. Use encodeURIComponent() for query parameter values.
Parse any URL and see every component clearly — protocol, domain, path, query, fragment
Try URL Parser Free →
