-
Notifications
You must be signed in to change notification settings - Fork 2
/
domain.py
36 lines (32 loc) · 897 Bytes
/
domain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## @file domain.py
#
# @brief this file contains the functions to extract the domain out of the urls
#
# @author Jodie
#
# @section libraries_main Libraries/Modules
# - urllib.parse standard library
# - access to urlparse function
# Imports
from urllib.parse import urlparse
# Get domain name (example.com)
def get_domain_name(url):
"""! This method extracts the domain name out of the url
@param url website link
@return domain name of the url
"""
try:
results = get_sub_domain_name(url).split('.')
return results[-2] + '.' + results[-1]
except:
return ''
# Get sub domain name (name.example.com)
def get_sub_domain_name(url):
"""! This method extracts the sub domain name out of the url
@param url website link
@return sub domain name of the url
"""
try:
return urlparse(url).netloc
except:
return ''