从另一个列表中的url中提取域名



从另一个列表中的url中提取域名。您还需要提取url以之结束的结束字符串。例如:https://www.example.com/market.php——在本例中,域名为www.example.com,结束字符串为php

Extract the domains and the ending string
# List of urls
url_list = ['https://blog.hubspot.com/marketing/parts-url',
'https://www.almabetter.com/enrollments',
'https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rename.html',
'https://www.programiz.com/python-programming/list']

urllib中使用urlparse(url)!(from urllib.parse import urlparse):

parsed_url = urlparse(url)
domain = parsed_url.netloc
ending = parsed_url.path.split('.')[-1]

最新更新