Last active
October 18, 2017 01:48
-
-
Save icarofreire/4eed182f5cd38b08e318da4d37721706 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package robo; | |
| import java.awt.AWTException; | |
| import java.awt.Robot; | |
| import java.awt.event.KeyEvent; | |
| import java.io.IOException; | |
| import java.net.URISyntaxException; | |
| import java.nio.charset.Charset; | |
| import java.nio.charset.StandardCharsets; | |
| import java.nio.file.Files; | |
| import java.nio.file.Path; | |
| import java.nio.file.Paths; | |
| import java.io.BufferedWriter; | |
| import java.io.FileWriter; | |
| import org.openqa.selenium.By; | |
| import org.openqa.selenium.Cookie; | |
| import org.openqa.selenium.WebDriver; | |
| import org.openqa.selenium.firefox.FirefoxDriver; | |
| import org.openqa.selenium.WebElement; | |
| import org.openqa.selenium.chrome.ChromeDriver; | |
| import java.awt.Toolkit; | |
| import java.awt.datatransfer.Clipboard; | |
| import java.awt.datatransfer.DataFlavor; | |
| import java.awt.datatransfer.StringSelection; | |
| import java.awt.datatransfer.UnsupportedFlavorException; | |
| import javax.swing.JOptionPane; | |
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.HashMap; | |
| import java.util.Set; | |
| import java.util.Vector; | |
| import java.util.regex.Matcher; | |
| import java.util.regex.Pattern; | |
| import java.io.BufferedReader; | |
| import java.io.FileReader; | |
| import java.io.IOException; | |
| public class Robo { | |
| private static int inf = 10000; | |
| public static void iniciar(int inicio, int fim) { | |
| int n_inf = 0; | |
| lib_rb rb = new lib_rb(); | |
| for(int i=inicio; i<fim; i++) { | |
| String url = "https://protegido.site/icempre7.com.br/administracao/index.php/distribuidores/editar_distribuidor/"; | |
| url += Integer.toString(i); | |
| rb.abrir_url(url); | |
| rb.esperar(3); | |
| boolean dados = rb.pegar_dados(i); | |
| int con_while = 0; | |
| while( dados == false ) { | |
| rb.f5(); | |
| rb.esperar(5); | |
| con_while++; | |
| dados = rb.pegar_dados(i); | |
| if( con_while > 10 ) { | |
| n_inf++; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ERRO-ROBO.TXT", "Erro ao pegar os dados do id do usuario: " + Integer.toString(i)); | |
| break; | |
| } | |
| }//fim while; | |
| if(n_inf > 2) { | |
| JOptionPane.showMessageDialog(null, "Erro, não obtem mais dados, mesmo atualizando a pagina.\nRecomece."); | |
| break; | |
| } | |
| rb.fechar_aba(); | |
| rb.esperar(1); | |
| }//fim for; | |
| JOptionPane.showMessageDialog(null, "Fim!"); | |
| } | |
| public static int nthIndexOf(String source, String sought, int n) { | |
| int index = source.indexOf(sought); | |
| if (index == -1) return -1; | |
| for (int i = 1; i < n; i++) { | |
| index = source.indexOf(sought, index + 1); | |
| if (index == -1) return -1; | |
| } | |
| return index; | |
| } | |
| public static String pegar(String clip, int _td, int _ftd, int _li, int _fli) { | |
| int td = nthIndexOf(clip, "<td>", _td); | |
| int ftd = nthIndexOf(clip, "</td>", _ftd); | |
| String patr = clip.substring(td+4, ftd).trim(); | |
| int li = nthIndexOf(clip, "<li>", _li); | |
| int fli = nthIndexOf(clip, "</li>", _fli); | |
| String linid = clip.substring(li, fli).trim(); | |
| int bb = nthIndexOf(linid, "/", 8); | |
| int as = nthIndexOf(linid, "\"", 2); | |
| String IDcliente = linid.substring(bb+1, as); | |
| return ( IDcliente + " - " + patr ); | |
| } | |
| public static void pegar_id_cliente_e_patrocinador(int ini) { | |
| lib_rb rb = new lib_rb();//5820 | |
| cb _cb = new cb(); | |
| String url1 = "https://protegido.site/icempre7.com.br/administracao/index.php/distribuidores/index/"; | |
| String url2 = "?pais=&planos=&usuario=&nome=&cpf=&uf=&conta_verificada=&di_login_status=&qualificado=&cep_de=&cep_ate=&ativo_mensalmente=?pais=&planos=&usuario=&nome=&cpf=&uf=&conta_verificada=&di_login_status=&qualificado=&cep_de=&cep_ate=&ativo_mensalmente="; | |
| for(int i=ini; i<=5925; i+=15) { | |
| String url = url1 + Integer.toString(i) + url2; | |
| rb.abrir_url(url); | |
| rb.esperar(3); | |
| rb.verificar_se_pagina_foi_carregada("Todos os direitos reservados"); | |
| rb.apagar_cb(); | |
| rb.ctrl_u(); | |
| rb.esperar(5); | |
| rb.verificar_se_pagina_foi_carregada("</html>"); | |
| String clip = _cb.colado(); | |
| while( clip == "" ) clip = _cb.colado(); | |
| if( clip != "-1" ) | |
| { | |
| int lifli = 111; | |
| try { | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 3, 4, 111, 111) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 14, 15, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 25, 26, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 36, 37, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 47, 48, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 58, 59, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 69, 70, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 80, 81, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 91, 92, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 102, 103, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 113, 114, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 124, 125, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 135, 136, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 146, 147, lifli, lifli) ); | |
| lifli+=9; | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", pegar(clip, 157, 158, lifli, lifli) ); | |
| }catch (Exception e) { | |
| JOptionPane.showMessageDialog(null, "Exception!"); | |
| System.out.println( e.getMessage() ); | |
| rb.REescrever("D:\\Documentos\\projeto-robo\\ERRO-CODIGO.TXT", "Erro em: " + Integer.toString(i) + ".\n[[" + clip + "]]\n Reiniciar em: " + (i-15) ); | |
| break; | |
| } | |
| rb.escrever("D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.TXT", "***********************************/\\" + Integer.toString(i) ); | |
| rb.REescrever("D:\\Documentos\\projeto-robo\\ULTIMO-PATROCINADOR-INSERIDO.TXT", Integer.toString(i) ); | |
| }//fim if; | |
| rb.apagar_cb(); | |
| rb.fechar_aba(); | |
| rb.esperar(1); | |
| rb.fechar_aba(); | |
| }//fim for; | |
| JOptionPane.showMessageDialog(null, "Fim!"); | |
| // String clip = rb.clipboard_to_string(); | |
| // int lifli = 111; | |
| // System.out.println( pegar(clip, 3, 4, 111, 111) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 14, 15, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 25, 26, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 36, 37, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 47, 48, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 58, 59, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 69, 70, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 80, 81, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 91, 92, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 102, 103, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 113, 114, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 124, 125, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 135, 136, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 146, 147, lifli, lifli) ); | |
| // lifli+=9; | |
| // System.out.println( pegar(clip, 157, 158, lifli, lifli) ); | |
| } | |
| public static void pegar_codigo_pagina_cliente(int inicio, int fim) { | |
| lib_rb rb = new lib_rb();//5820 | |
| cb _cb = new cb(); | |
| for(int i=inicio; i<fim; i++) { | |
| String url = "https://protegido.site/icempre7.com.br/administracao/index.php/distribuidores/editar_distribuidor/"; | |
| url += Integer.toString(i); | |
| rb.abrir_url(url); | |
| rb.esperar(3); | |
| rb.verificar_se_pagina_foi_carregada("Todos os direitos reservados"); | |
| rb.apagar_cb(); | |
| rb.ctrl_u(); | |
| rb.esperar(5); | |
| rb.verificar_se_pagina_foi_carregada("</html>"); | |
| String clip = _cb.colado(); | |
| while( clip == "" ) clip = _cb.colado(); | |
| if( clip != "-1" ) | |
| { | |
| try { | |
| rb.REescrever("D:\\Documentos\\projeto-robo\\paginas\\PAG-DIST-" + Integer.toString(i) + ".TXT", clip ); | |
| }catch (Exception e) { | |
| JOptionPane.showMessageDialog(null, "Exception!"); | |
| System.out.println( e.getMessage() ); | |
| rb.REescrever("D:\\Documentos\\projeto-robo\\ERRO-CODIGO.TXT", "Erro em: " + Integer.toString(i) + ".\n[[" + clip + "]]\n Reiniciar em: " + (i-15) ); | |
| break; | |
| } | |
| rb.REescrever("D:\\Documentos\\projeto-robo\\ULTIMO-DISTRIBUIDOR-INSERIDO.TXT", Integer.toString(i) ); | |
| }//fim if; | |
| rb.apagar_cb(); | |
| // rb.fechar_aba(); | |
| rb.alt_w(); | |
| rb.esperar(1); | |
| // rb.fechar_aba(); | |
| }//fim for; | |
| JOptionPane.showMessageDialog(null, "Fim!"); | |
| } | |
| public static String[] remover_dado_array(String[] titulos, String dado) { | |
| ArrayList<String> a = new ArrayList<>(Arrays.asList(titulos)); | |
| a.remove(dado); | |
| titulos = new String[a.size()]; | |
| return a.toArray(titulos); | |
| } | |
| public static String[] diff(String[] arr) { | |
| for (int i = 0; i < arr.length; i++) { | |
| for (int j = 0; j < arr.length; j++) { | |
| if( (i!=j) && arr[i].equals(arr[j]) ) { | |
| arr[j] = arr[j] + "_da_entrega"; | |
| } | |
| } | |
| } | |
| return arr; | |
| } | |
| public static void ler_arquivo_e_criar_inserts_dados_clientes() { | |
| lib_rb rb = new lib_rb(); | |
| int con = 0; | |
| String FILENAME = "D:\\Documentos\\projeto-robo\\RES-ROBO-2.txt"; | |
| try (BufferedReader br = new BufferedReader(new FileReader(FILENAME))) { | |
| String linha; | |
| while ((linha = br.readLine()) != null) { | |
| con++; | |
| String[] valores = linha.split("\\:\\=\\=\\>(.[^\\;]*)\\;"); | |
| String[] titulos = linha.split("\\[\\#\\#\\](.[^\\:\\=\\=\\>]*)\\:\\=\\=\\>"); | |
| titulos = remover_dado_array(titulos, ""); | |
| titulos = remover_dado_array(titulos, "---##################################################################################"); | |
| valores = remover_dado_array(valores, ""); | |
| valores = remover_dado_array(valores, "---##################################################################################"); | |
| if( titulos.length == valores.length ) | |
| { | |
| String sql = "INSERT INTO tabela ("; | |
| for (int i = 0; i < valores.length; i++) { | |
| String vir = ""; | |
| if( i < (valores.length-1) ) { | |
| vir = ","; | |
| }else { vir = ")"; } | |
| sql += valores[i].replaceAll("\\[\\#\\#\\]", "").replaceAll(" ", "_").replaceAll("\\'", "\'") + vir; | |
| } | |
| sql += " VALUES ("; | |
| for (int i = 0; i < titulos.length; i++) { | |
| String vir = ""; | |
| if( i < (titulos.length-1) ) { | |
| vir = ","; | |
| }else { vir = ")"; } | |
| String dados = "'" + titulos[i].replaceAll("\\;", "").replaceAll("\\'", "\'") + "'" + vir; | |
| sql += dados; | |
| } | |
| sql += ";"; | |
| if( !sql.equals("INSERT INTO tabela ( VALUES (;") ) { | |
| // System.out.println(sql); | |
| rb.escrever("D:\\Documentos\\projeto-robo\\INSERTS-DADOS-CLIENTES.txt", sql); | |
| } | |
| }//fim if; | |
| // if(con > 10) break; | |
| } | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| System.out.println("Fim."); | |
| } | |
| public static void ler_arquivo_e_criar_inserts_patrocinadores() { | |
| lib_rb rb = new lib_rb(); | |
| int con = 0; | |
| String FILENAME = "D:\\Documentos\\projeto-robo\\ID-PATROCINADORES.txt"; | |
| try (BufferedReader br = new BufferedReader(new FileReader(FILENAME))) { | |
| String linha; | |
| while ((linha = br.readLine()) != null) { | |
| con++; | |
| String sql = ""; | |
| int ifen = linha.indexOf(" - "); | |
| if( ifen != -1 ) { | |
| sql = "INSERT INTO tabela (ID_CLIENTE,PATROCINADOR) VALUES ("; | |
| sql += "'" + linha.substring(0, ifen).trim() + "','" + linha.substring(ifen+2).replaceAll("\\'", "\'").trim() + "'"; | |
| sql += ");"; | |
| } | |
| if( !sql.isEmpty() ) { | |
| // System.out.println( sql ); | |
| rb.escrever("D:\\Documentos\\projeto-robo\\INSERTS-PATROCINADORES.txt", sql); | |
| } | |
| // if(con > 10) break; | |
| } | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| System.out.println("Fim."); | |
| } | |
| public static void sendKeys(Robot robot, String keys) { | |
| for (char c : keys.toCharArray()) { | |
| int keyCode = KeyEvent.getExtendedKeyCodeForChar(c); | |
| if (KeyEvent.CHAR_UNDEFINED == keyCode) { | |
| throw new RuntimeException( | |
| "Key code not found for character '" + c + "'"); | |
| } | |
| robot.keyPress(keyCode); | |
| // robot.delay(100); | |
| robot.keyRelease(keyCode); | |
| // robot.delay(100); | |
| } | |
| } | |
| public static String pegar_subs(String linha, String alvo1, String alvo2) { | |
| String subs = "-1"; | |
| int ind1 = linha.indexOf(alvo1); | |
| int ind2 = linha.indexOf(alvo2, ind1); | |
| if( ind1 != -1 && ind2 != -1 ) { | |
| subs = linha.substring(ind1+alvo1.length(), ind2); | |
| } | |
| return subs; | |
| } | |
| public static String arquito_to_string(String arquivo) { | |
| Path path = Paths.get(arquivo); | |
| // Charset charset = StandardCharsets.UTF_8; | |
| String content = ""; | |
| try { | |
| content = new String(Files.readAllBytes(path)/*, charset*/); | |
| } catch (IOException e) { | |
| // TODO Auto-generated catch block | |
| e.printStackTrace(); | |
| } | |
| return content; | |
| } | |
| public static void ler_arquivos_e_pegar_dados() { | |
| HashMap<String, String> mapa = new HashMap<String, String>(); | |
| Vector<String> titulos = new Vector<String>(); | |
| titulos.add("numero_pin"); | |
| titulos.add("usuario"); | |
| titulos.add("email"); | |
| titulos.add("nome"); | |
| titulos.add("ultimo_nome"); | |
| titulos.add("tipo_documento"); | |
| titulos.add("numero_do_documento"); | |
| titulos.add("telefone"); | |
| titulos.add("celular"); | |
| titulos.add("data_de_nascimento"); | |
| titulos.add("lugar_do_nascimento"); | |
| titulos.add("sexo"); | |
| titulos.add("pais"); | |
| titulos.add("estado"); | |
| titulos.add("cidade"); | |
| titulos.add("endereco"); | |
| titulos.add("numero"); | |
| titulos.add("complemento"); | |
| titulos.add("cep"); | |
| titulos.add("bairro"); | |
| titulos.add("pais_da_entrega"); | |
| titulos.add("estado_da_entrega"); | |
| titulos.add("cidade_da_entrega"); | |
| titulos.add("endereco_da_entrega"); | |
| titulos.add("numero_da_entrega"); | |
| titulos.add("complemento_da_entrega"); | |
| titulos.add("cep_da_entrega"); | |
| titulos.add("bairro_da_entrega"); | |
| String FILENAME = "D:\\Documentos\\projeto-robo\\paginas\\PAG-DIST-503.txt"; | |
| try (BufferedReader br = new BufferedReader(new FileReader(FILENAME))) { | |
| String arquivo = arquito_to_string(FILENAME); | |
| String alvo1 = "<input name=\"di_email\" id=\"di_email\" type=\"text\" size=\"50\" class=\"validar-atm\" value=\""; | |
| String alvo2 = "\" />"; | |
| String subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("email", subs); | |
| } | |
| } | |
| //nome | |
| alvo1 = "<input name=\"di_nome\" id=\"di_nome\" type=\"text\" class=\"validate[required] so_letras\" size=\"50\" value=\""; | |
| alvo2 = "\" />"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("nome", subs); | |
| } | |
| } | |
| //ultimo nome | |
| alvo1 = "<input name=\"di_ultimo_nome\" id=\"di_ultimo_nome\" type=\"text\" class=\"validate[required] so_letras\" size=\"50\" value=\""; | |
| alvo2 = "\" />"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("ultimo_nome", subs); | |
| } | |
| } | |
| //tipo documento | |
| alvo1 = "<option selected value=\""; | |
| alvo2 = "</option>"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ) { | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| // subs = pegar_subs(subs, "selected value=\"", "</option>"); | |
| subs = subs.substring(subs.indexOf(">")+1); | |
| } | |
| // System.out.println( "[[" + subs + "]]" ); | |
| mapa.put("tipo_documento", subs); | |
| } | |
| //numero do documento | |
| alvo1 = "<input name=\"di_rg\" id=\"di_rg\" type=\"text\" size=\"50\" value=\""; | |
| alvo2 = "\" class=\""; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("numero_do_documento", subs); | |
| } | |
| } | |
| //telefone | |
| alvo1 = "Telefone:</label>"; | |
| alvo2 = "name=\"di_fone1\""; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ) { | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| // subs = pegar_subs(subs, "value=\"", "\" "); | |
| subs = subs.substring(subs.indexOf("value=\"")+7).replaceAll("\"", ""); | |
| } | |
| // System.out.println( "[[" + subs + "]]" ); | |
| mapa.put("telefone", subs); | |
| } | |
| //celular | |
| alvo1 = "Celular:</label>"; | |
| alvo2 = "\" name=\"di_fone2\""; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ) { | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| // subs = pegar_subs(subs, "value=\"", "\" "); | |
| subs = subs.substring(subs.indexOf("value=\"")+7); | |
| } | |
| // System.out.println( "[[" + subs + "]]" ); | |
| mapa.put("celular", subs); | |
| } | |
| // \/data de nascimento: | |
| alvo1 = "Data de Nascimento:"; | |
| alvo2 = "\" placeholder=\"dd/mm/aaaa\""; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ) { | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| // subs = pegar_subs(subs, "value=\"", "\" "); | |
| subs = subs.substring(subs.indexOf("value=\"")+7); | |
| } | |
| // System.out.println( "[[" + subs + "]]" ); | |
| mapa.put("data_de_nascimento", subs); | |
| } | |
| //lugar do nascimento | |
| alvo1 = "Lugar do nascimento:"; | |
| alvo2 = "\" class=\"validate[required] so_letras\">"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ) { | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| // subs = pegar_subs(subs, "value=\"", "\" "); | |
| subs = subs.substring(subs.indexOf("value=\"")+7); | |
| } | |
| // System.out.println( "[[" + subs + "]]" ); | |
| mapa.put("lugar_do_nascimento", subs); | |
| } | |
| //sexo | |
| alvo1 = "Sexo:"; | |
| alvo2 = "</select>"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ) { | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| subs = pegar_subs(subs, "selected value=\"", "</option>"); | |
| subs = subs.substring(subs.indexOf(">")+1); | |
| } | |
| // System.out.println( "[[" + subs + "]]" ); | |
| mapa.put("sexo", subs); | |
| } | |
| //pais | |
| alvo1 = "name=\"di_pais\" id=\"di_pais\""; | |
| alvo2 = "</select>"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ) { | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| subs = pegar_subs(subs, "selected>", "</option>").trim(); | |
| } | |
| // System.out.println( "[[" + subs + "]]" ); | |
| mapa.put("pais", subs); | |
| } | |
| //estado | |
| alvo1 = "selected=\"selected\""; | |
| alvo2 = "</option>"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ) { | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| subs = subs.substring(subs.indexOf(">")+1); | |
| } | |
| // System.out.println( "[[" + subs + "]]" ); | |
| mapa.put("estado", subs); | |
| } | |
| //cidade | |
| alvo1 = "<input type=\"text\" name=\"di_cidade\" id=\"di_cidade\" autocomplete=\"off\" value=\""; | |
| alvo2 = "\" class=\"so_letras\"/>"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("cidade", subs); | |
| } | |
| } | |
| //endereço | |
| alvo1 = "<input type=\"text\" name=\"di_endereco\" id=\"di_endereco\" value=\""; | |
| alvo2 = "\" size=\"50\""; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("endereco", subs); | |
| } | |
| } | |
| //numero | |
| alvo1 = "<input type=\"text\" class=\"validate[required]\" id=\"di_numero\" value=\""; | |
| alvo2 = "\" name=\"di_numero\""; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("numero", subs); | |
| } | |
| } | |
| //complemento | |
| alvo1 = "<input type=\"text\" id=\"di_complemento\" name=\"di_complemento\" value=\""; | |
| alvo2 = "\" size=\"14\">"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("complemento", subs); | |
| } | |
| } | |
| //cep | |
| alvo1 = "<input type=\"text\" name=\"di_cep\" id=\"di_cep\" value=\""; | |
| alvo2 = "\" class=\"validate"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("cep", subs); | |
| } | |
| } | |
| //bairro | |
| alvo1 = "<input type=\"text\" name=\"di_bairro\" id=\"di_bairro\" size=\"30\" value=\""; | |
| alvo2 = "\" />"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("bairro", subs); | |
| } | |
| } | |
| //pais da entrega | |
| alvo1 = "<select name=\"end_pais\""; | |
| alvo2 = "</select>"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ) { | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| subs = pegar_subs(subs, "selected value=\"", "</option>"); | |
| subs = subs.substring(subs.indexOf(">")+1); | |
| } | |
| // System.out.println( "[[" + subs + "]]" ); | |
| mapa.put("pais_da_entrega", subs); | |
| } | |
| //estado da entrega | |
| alvo1 = "Estado:"; | |
| alvo2 = "</option></select>"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ) { | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| subs = pegar_subs(subs, "selected=\"selected\"", "</option>"); | |
| subs = subs.substring(subs.indexOf(">")+1); | |
| } | |
| // System.out.println( "[["+subs+"]]" ); | |
| mapa.put("estado_da_entrega", subs); | |
| } | |
| //cidade da entrega | |
| alvo1 = "<input type=\"text\" name=\"di_cidade\" id=\"di_cidade\" autocomplete=\"off\" value=\""; | |
| alvo2 = "\" class=\"so_letras\"/>"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("cidade_da_entrega", subs); | |
| } | |
| } | |
| //endereço da entrega | |
| alvo1 = "<input type=\"text\" name=\"di_endereco\" id=\"di_endereco\" value=\""; | |
| alvo2 = "\" size=\"50\" style"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("endereco_da_entrega", subs); | |
| } | |
| } | |
| //numero da entrega | |
| alvo1 = "<input type=\"text\" class=\"validate[required]\" id=\"di_numero\" value=\""; | |
| alvo2 = "\" name=\"di_numero\""; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("numero_da_entrega", subs); | |
| } | |
| } | |
| //complemento da entrega | |
| alvo1 = "<input type=\"text\" id=\"di_complemento\" name=\"di_complemento\" value=\""; | |
| alvo2 = "\" size=\"14\""; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("complemento_da_entrega", subs); | |
| } | |
| } | |
| //cep da entrega | |
| alvo1 = "<input type=\"text\" name=\"di_cep\" id=\"di_cep\" value=\""; | |
| alvo2 = "\" class=\"validate"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("cep_da_entrega", subs); | |
| } | |
| } | |
| //bairro da entrega | |
| alvo1 = "<input type=\"text\" name=\"di_bairro\" id=\"di_bairro\" size=\"30\" value=\""; | |
| alvo2 = "\" />"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("bairro_da_entrega", subs); | |
| } | |
| } | |
| //usuario | |
| alvo1 = "<input type=\"text\" id=\"di_usuario\" name=\"di_usuario\" value=\""; | |
| alvo2 = "\" class=\"so_letras_numeros\"/>"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("usuario", subs); | |
| } | |
| } | |
| //pin | |
| alvo1 = "<span rel=\"tooltip\" data-placement=\"bottom\" title=\""; | |
| alvo2 = "\" id=\"tool\">"; | |
| subs = pegar_subs(arquivo, alvo1, alvo2); | |
| if( !subs.equals("-1") ){ | |
| if( subs.isEmpty() ) { | |
| subs = "vazio"; | |
| }else { | |
| mapa.put("numero_pin", subs); | |
| } | |
| } | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| for (int i = 0; i < titulos.size(); i++) { | |
| System.out.println( titulos.get(i) + "->" + mapa.get(titulos.get(i)) ); | |
| } | |
| } | |
| public static void main(String[] args) throws AWTException { | |
| // int fim = 5482; | |
| // iniciar(3656,fim); | |
| // pegar_id_cliente_e_patrocinador(5910 + 15); | |
| // ler_arquivo_e_criar_inserts_dados_clientes(); | |
| // ler_arquivo_e_criar_inserts_patrocinadores(); | |
| int fim = 6641; | |
| pegar_codigo_pagina_cliente(888, fim); | |
| // ler_arquivos_e_pegar_dados(); | |
| // System.setProperty("webdriver.chrome.driver", "D:\\Downloads\\selenium\\chromedriver.exe"); | |
| // WebDriver driver = new ChromeDriver(); | |
| // driver.get("http://google.com"); | |
| // driver.navigate().to("http://stackoverflow.com"); | |
| // Path path = Paths.get("D:\\Documentos\\projeto-robo\\teste-robo.txt"); | |
| // Charset charset = StandardCharsets.UTF_8; | |
| // | |
| // String content; | |
| // try { | |
| // content = new String(Files.readAllBytes(path), charset); | |
| // content = content.replaceAll("(.*\\:\\=\\=\\>)", "[##]$1"); | |
| // | |
| // content = content.replaceAll("(\\[\\#\\#\\])(.[^\\[]*)\\[", "$1$2[");//ate | |
| // | |
| // content = content.replaceAll("(\\: )(.*)", ":==>$2"); | |
| // content = content.replaceAll("(ID\\:\\=\\=\\>)", "[##]ID:==>"); | |
| // content = content.replaceAll("(Nº PIN\\:\\=\\=\\>)", "[##]Nº PIN:==>"); | |
| // content = content.replaceAll("\\>\r\n(.[^\\[\r\n]*)", ">$1;"); | |
| // | |
| // System.out.println( content ); | |
| //// Files.write(path, content.getBytes(charset)); | |
| // } catch (IOException e) { | |
| // // TODO Auto-generated catch block | |
| // e.printStackTrace(); | |
| // } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment