#S0015. 完整版 URL 解析
完整版 URL 解析
1. Description
Create a smart URL parser. Every URL contains these key components:
- Protocol: Delivery method (http/https)
- Domain: Receiver's address (like
google.com) - Port: Door number (default: 80 for http, 443 for https)
- Path: Room number (e.g.
/search) - Parameters: Delivery notes (e.g.
?q=python)
Program should output:
- Protocol
- Domain
- Port (auto-select if missing)
- Path (default
/) - Parameter dictionary
2. Input & Output
Input:
- A single string
url = input().strip()
Output:
- First 4 lines: protocol, domain, port, path
- 5th line: parameter dict (empty if none)
Example
# Input:
ftp://files.net:2100/docs?file=readme.txt
# Output:
Protocol:ftp
Domain:files.net
Port:2100
Path:/docs
{'file':'readme.txt'}