Complete the code to extract the protocol from the URL string.
url = "https://example.com" protocol = url.split('[1]')[0]
The protocol part of a URL ends with '://'. Splitting the URL by '://' separates the protocol from the rest.
Complete the code to get the domain name from the URL.
url = "https://example.com/path" domain = url.split('[1]')[1].split('/')[0]
Splitting by '//' separates the protocol from the domain and path. The domain is the first part after '//', before the next '/'.
Complete the code to correctly extract the path from the URL.
url = "https://example.com/path/to/page" path = url.split('//')[1].split('[1]', 1)[1]
Split by '//' to get domain+path, then split that by '/' (maxsplit=1) to separate the domain from the path. Index [1] gives 'path/to/page'.
Fill both blanks to create a dictionary mapping URL parts to their values.
url = "https://example.com:8080/path?query=1" parts = { 'protocol': url.split('[1]')[0], 'port': url.split(':')[[2]].split('/')[0] }
Splitting by '://' separates the protocol. The port is after the second colon, so index 2 after splitting by ':'.
Fill all three blanks to extract query parameters as a dictionary.
url = "https://example.com/path?user=alice&age=30" query_string = url.split('[1]')[1] params = {param.split('[2]')[0]: param.split('[2]')[1] for param in query_string.split('[3]')}
The query string starts after '?'. Each parameter is split by '&'. Each key and value are separated by '='.