Error time out when parsing with .visit ()

0

I am parsing using .visit () with this code:

String link = "Aquí iría la URL";                                    
Document doc = ScrapingUtils.visit(link, false);

The fact is that sometimes for whatever reason you can not access the page, and you send me a error time out . I would like to collect when this happens in order to give a concrete value to the variables in which the elements I am extracting are stored, but I can not find the form.

After that code I only have one conditional if such that:

if (doc != null) {
   //código
else {
   //código
}

The only thing I can think of is with a try / catch just before the conditional. That is:

String link = "Aquí iría la URL";                                    
Document doc = ScrapingUtils.visit(link, false);

try {
    if (doc != null) {
       //código
    else {
       //código
    }
catch () {
}
    
asked by JetLagFox 19.06.2018 в 14:09
source

1 answer

1

I can think of something like this:

 try {
        if (doc != null) {
           //código
        else {
           //código
        }
      }
     catch (  TimeoutException exception) {
        throw new TimeoutException("Tiempo excedido: " + timeout + unit);
      }

and in the catch you enter the values you want for the variables.

    
answered by 19.06.2018 в 14:26