Skip to content

Commit

Permalink
Adicionado método para remover o http:// dos links
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobbbs committed Sep 9, 2011
1 parent c0ace27 commit 8f2ea58
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions GetHeader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,48 @@ def __init__(self, *args):
def get_url(self):
return self._url

def set_url(self, link):
self._url = link

def get_error(self, num):
erros = {1:"Falha na conexão: O host conectado não respondeu!"}
return erros[num]

def __remove_http(self):
"""
Remove o HTTP:// antes do link para evitar erros na conexão
"""
links = self.get_url()
new_link = []
for link in links:
if "http://" in link:
new_link.append(link[7:])
self.set_url(new_link)

def get_cabecalho(self):

#TODO: Criar método para dividir o link depois do '/', se houver, para passar em 'end_url' no get_cabecalho


def get_cabecalho(self, end_url="/"):
"""
Este método efetua uma conexão com os links passados, afim de obter seu código http
"""

links = self.get_url()
result = {}

for link in links:

# Faz a conexão em cada um dos links para buscar o cabeçalho
conn = httplib.HTTPConnection(link)
try:
conn.request("GET", "/")
conn.request("GET", end_url)
except socket.error:
return self.get_error(1)

result = conn.getresponse()
cod_http = conn.getresponse()

result[link] = cod_http.status, cod_http.reason

return result.status, result.reason
return result

0 comments on commit 8f2ea58

Please sign in to comment.