I have developed the following código
to get the content of a certain webpage:
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Logger logger= Logger.getLogger("org.bonitasoft");
URL url = null;
File file = new File("C:\Backup\page.html");
def x = 1;
//while (x = 1){
url = new URL("http://site");
BufferedReader inFile = new BufferedReader(new InputStreamReader(url.openStream()));
BufferedWriter outFile = new BufferedWriter(new FileWriter(file));
String inputLine;
while ((inputLine = inFile.readLine()) != null) {
Matcher matcherRamo = Pattern.compile("Ramo:\s<.strong>\s.*").matcher(inputLine)
Matcher matcherNome = Pattern.compile("consulta-associados-item-nome-fantasia").matcher(inputLine)
Matcher matcherFone = Pattern.compile("<strong>Fone: <.strong>").matcher(inputLine)
Matcher matcherEmail = Pattern.compile("<strong>Email: <.strong> <a href=\"mailto:.*\" class=\"link\">").matcher(inputLine)
Matcher matcherProduto = Pattern.compile("<span class=\"float-left\">").matcher(inputLine)
Matcher matcherSite = Pattern.compile("<strong>Site: <.strong>\s<a href=.* target=\"_blank\">").matcher(inputLine)
if (matcherNome.find()){
logger.info("NOME: "+inputLine.replace("<h3 class=\"consulta-associados-item-nome-fantasia\">", "").replace("</h3>", "").trim())
}
if (matcherFone.find()){
logger.info("TELEFONE: "+inputLine.replace("<strong>Fone: </strong>", "").trim())
}
if (matcherEmail.find()){
logger.info("EMAIL: "+inputLine.replaceFirst("<strong>Email: <.strong> <a href=\"mailto:.*\" class=\"link\">", "").replace("</a>", "").trim())
}
if (matcherRamo.find()){
logger.info("RAMO: "+inputLine.replace("Ramo: </strong> ", "").replace("<strong>", "").trim())
}
if (matcherProduto.find()){
logger.info("PRODUTO: "+inputLine.replace("<span class=\"float-left\">", "").replace("</span>", "").replace("<br>", " | ").trim())
}
if (matcherSite.find()){
logger.info("SITE: "+inputLine.replaceFirst("<strong>Site: <.strong>\s<a href=.* target=\"_blank\">", "").replace("</a>", "").trim())
}
outFile.write(inputLine);
outFile.newLine();
}
//x++
//}
inFile.close();
outFile.flush();
outFile.close();
He is picking up correctly the information I need but when the process is finished, finished reading the entire page and returned the filtered content he starts doing the same again, infinitely, if you can help me thank you.