2
I developed the following código
to take the content of a given web page:
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 correctly picking up the information I need but when the process is finished, finished reading the entire page and returned me the filtered content he starts to do again the same thing, infinitely, if you can help me thank.
Just out of curiosity, what is/does
def x = 1;
?– igventurelli
@Igorventurelli It was an unsuccessful test kk
– R.Santos
Put the complete code.. There is no definition of class or method.. It is difficult to understand hehe
– igventurelli
@Igorventurelli this is the complete code, I have nothing else
– R.Santos
There’s... there’s not one
public class Classe { }
._. That’s right?– igventurelli
@Igorventurelli, I’m sorry, I forgot to add to tag groovy, I put the Java for being extremely similar but it’s a groovy script
– R.Santos
Let’s go continue this discussion in chat.
– R.Santos