tupla = (i[0:14], "buscarPadrao") listaDeCnpjs.append(tupla) arquivo.close() for tupla in listaDeCnpjs: chave = Chave(tupla[0], tupla[1]) continuarProcurando = True chaveCancelada = 0 while continuarProcurando: cnpj = chave.getCnpj() encontrouXML = "nao" ini = time.time() while encontrouXML=="nao": try: browser = mechanize.Browser() browser.set_handle_robots(False) nfeEndereco = 'http://nfe.sefaz.pe.gov.br/nfe-web/' endereco1 = "%sentradaConsNfe?tp=C" % nfeEndereco html = browser.open(endereco1) soup = BeautifulSoup(html) image_tags = soup.findAll('img') i=0 for image in image_tags:
chaveTemp = Chave(tupla[0], tupla[1]) chavePivor = Chave(tupla[0], tupla[1]) procurandoAbaixo = True etapa1 = 0 contaErro = 0 continuarProcurando = True deuSalto = False chaveCancelada = 0 saltoValido = False while continuarProcurando: encontrouXML = "nao" ini = time.time() if not os.path.exists('./Notas/'+chave.getCnpj()): os.mkdir ('./Notas/'+chave.getCnpj()) os.mkdir ('./Notas/'+chave.getCnpj()+'/canceladas') print "----------------------------------------------------------------------" print "Diretorio criado - ", chave.getCnpj() print "----------------------------------------------------------------------" else: if not os.path.exists('./Notas/'+chave.getCnpj()+'/canceladas'): os.mkdir ('./Notas/'+chave.getCnpj()+'/canceladas') if chave.existeChave(): print "Chave ja baixada - ",chave.getChave() encontrouXML = "sim" if int(chave.getNumero()) == 1: