-
Notifications
You must be signed in to change notification settings - Fork 6
/
URL.py
61 lines (47 loc) · 1.59 KB
/
URL.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import re
class URLParser:
def __init__(self, url):
self.url = url
@property
def path(self):
fulldomain = self.protocol + '://' + self.host + '.' + self.domain + '/'
# return self.url.replace(fulldomain, '')
path_with_params = self.url.replace(fulldomain, "")
return re.match(r'(.*)\?.*', path_with_params).group(1) if "?" in path_with_params else path_with_params
@property
def domain(self):
_url = self.url.replace(self.protocol + "://", "")
if self.host != "":
_url = _url.replace(self.host + ".", "")
return _url.split('/')[0]
@property
def protocol(self):
return re.match(r'(.*)://.*', self.url).group(1)
@property
def host(self):
_host = ''
if len(self.url.split('.')) > 2:
_host = self.url.split('://')[1].split('.')[0]
if not re.match(r'www.*', _host):
_host = ""
return _host
@property
def params(self):
return re.match(r'.*\?(.*)', self.url).group(1)
@property
def username(self):
return self.credentials.group(1)
@property
def password(self):
return self.credentials.group(2)
@property
def credentials(self):
return re.match(r'.*\://(.*)\:(.*)@.*', self.url)
def print_analisys(self):
return 'Entrada: ' + self.url + ' \
Saida: \
protocolo: ' + self.protocol + ' \
host: ' + self.host + ' \
dominio: ' + self.domain + ' \
path: ' + self.path + ' \
parametros: ' + self.params