Get image URL in Processing (JAVA)?

0

How can I get the URL of the images that are displayed in a viewer, from a page where I do not have the php code?

The page shows different images, with different urls, but always in a

<img id="imgVisor" src="...">

How can I obtain, to use in Processing, the URLs of those images?

Thank you very much

    
asked by thru. 28.09.2017 в 16:49
source

1 answer

0

Here is an example that I found here . The key is in URLConnection .

I hope it serves you. The code is not mine but it is easy to understand. You just have to apply it to look for you and filter the <img> tags and the src I think. I do not remember much of html.

package testurl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Testurl {

public static void main(String[] args) {
    try {
        //se abre la conexiòn
        URL url = new URL("http://www.cambioschaco.com.py/php/chaco_cotizaciones_nuevo.php");
        URLConnection conexion = url.openConnection();
        conexion.connect();

        //Lectura
        InputStream is = conexion.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        char[] buffer = new char[1000];
       //ACA EMPIEZA MI CONDICIÓN DESDE ACÁ PODES CAMBIAR VOS
        int leido;
        String texto = "";
        while ((leido = br.read(buffer)) > 0) {
            String datos = new String(buffer, 0, leido);
            texto += datos;
        }
        //---------------------------------------------------------------
        //AQUI EMPIEZA A FILTRAR EL TEXTO PARA OBTENER ETIQUETAS. PUEDES 
        //HACER LAS MODIFICACIONES DESDE ESTA PARTE. 
        //---------------------------------------------------------------
        String[] tr = texto.split("<tr");
        String fila = "";
        for (String linea : tr) {
            if (linea.contains("Dolar Americano")) {
                fila = linea;
            }
        }

        String[] td = fila.split("<td");
        String columna = "";
        for (String linea : td) {
            if (linea.contains(",00")) {
                System.out.println("---> " + linea);
                int pos1 = 0;
                int pos2 = 0;
                String cotizacion = "";
                for (int i = 0; i < linea.length(); i++) {
                    if (linea.substring(i, i + 1).equals(">")) {
                        pos1 = i;
                    } else if (linea.substring(i, i + 1).equals("<")) {
                        pos2 = i;
                        break;
                    }
                }
                System.out.println("---> " + linea.substring(pos1 + 1, pos2));
            }
        }
   //FIN DE LA CONDICION

    } catch (MalformedURLException ex) {
        Logger.getLogger(Testurl.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Testurl.class.getName()).log(Level.SEVERE, null, ex);
    }
}

}
    
answered by 28.09.2017 / 18:04
source