Lesson 1 of 0
In Progress

Parsing URLs

Kedeisha June 16, 2023

Write a Python function that parses a URL and returns a dictionary containing the protocol, domain and path. Use regular expressions for this task.

url = ‘https://example.com/path/to/page’ 

Explanation of Solution: The function parse_url accepts a single string as input. It defines a pattern that matches a string representing a URL and divides it into three groups: protocol, domain, and path. re.match function is used to check if the input string matches this pattern. If the match is found, the function returns a dictionary with the matched groups; otherwise, it returns None.