import re
class Extrator_url:
def __init__(self, url):
self.url = self.sanatiza_url(url)
self.validacao_url(url)
def sanatiza_url(self, url):
if url == str:
return url.strip()
else:
return ""
def validacao_url(self):
if not self.url:
raise ValueError("A url está vazia!")
padrao_url = re.compile("(http(s)?://)?(www.)?bytebank.com(.br)?/cambio")
match = padrao_url.match(self.url)
if not match:
raise ValueError("A url é inválida!")
def extrair_url_base(self):
indice_url_base = self.url.find('?')
url_base = self.url[:indice_url_base + 1]
return url_base
def url_parametros(self):
indice_url_base = self.url.find('?')
url_parametros = self.url[self.extrair_url_base() + 1:]
return url_parametros
def buscar_parametro(self, url_parametros):
indice_parametro = self.url_parametros().find(url_parametros)
indice_valor = indice_parametro + len(url_parametros) + 1
indice_e_comercial = self.url_parametros().find('&', indice_valor)
if indice_e_comercial == -1:
valor = self.url_parametros()[indice_valor:]
else:
valor = self.url_parametros()[indice_valor:indice_e_comercial]
return valor
extrator_url = Extrator_url("bytebank.com/cambio?moedaDestino=dolar&moedaOrigem=real")
valor_moeda_destino = extrator_url.buscar_parametro('moedaDestino')
print(valor_moeda_destino)
Erro apontado:
line 44, in <module>
extrator_url = Extrator_url("bytebank.com/cambio?moedaDestino=dolar&moedaOrigem=real")
line 6, in __init__
self.validacao_url(url)
TypeError: Extrator_url.validacao_url() takes 1 positional argument but 2 were given