Let say I want to parse a list of links and return that in a dictionary format
I am following along with an online course and I want to create a solution that can validate multiple links or a list of links, so how I go about that?
import re
def url_validate(input):
url_reg = re.compile(r'(https?)://(www\.[A-za-z-]{2,256}\.[a-z]{2,6})([-a-zA-Z0-9@:%_\+.~#?&//=]*)')
match = url_reg.search(input)
if match:
return dict(({
'Protocol': match.group(1),
'Domain': match.group(2),
'Remaining': match.group(3)
}))
return f"This is not url {input}"
url_validate("https://www.youtube.com/watch?v=emHAoQGoQic&list=LLEvmU2o3RMbp4lpXdKgfCnw&index=5&t=0s")
This works fine with one link though
Out:
{'Protocol': 'https',
'Domain': 'www.youtube.com',
'Remaining': '/watch?v=emHAoQGoQic&list=LLEvmU2o3RMbp4lpXdKgfCnw&index=5&t=0s'}