Pegar imagens de uma página HTML

2 respostas
F

Bom pessoal.
Preciso percorrer o código fonte de um site, identificar as imagens, salva-las em arquivo e aguardar numa pasta.
Estes são requisitos de um trabalho de redes. Pois bem eu parei em: percorrer o HTML e pegar ias imagens.
Alguém sabe como fazer?

Eis aí o código que faz a requisição e obtem a resposta do servidor.
Está assim porque só é permitido o uso da Classe Socket, ou seja, nada de URL, HttpURLConnection…

import java.io.*;
import java.net.*;

public class Main {

    public static final String TARGET_HTTPS_SERVER = "www.utfpr.edu.br";
    public static final int TARGET_HTTPS_PORT = 80;

    public static void main(String[] args) throws Exception {
        Socket socket = new Socket(TARGET_HTTPS_SERVER, TARGET_HTTPS_PORT);
        try {
            Writer out = new OutputStreamWriter(socket.getOutputStream());
            out.write("GET / HTTP/1.1\r\n");
            out.write("Host: " + TARGET_HTTPS_SERVER + ":" + TARGET_HTTPS_PORT + "\r\n");
            out.write("\r\n");
            out.flush();
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
        } finally {
            socket.close();
        }
    }
}

2 Respostas

F

Ninguém sabe?

Nem uma expressão regular para pegar as url das imagens?
Afinal o que preciso de inicio é isso, as url do tipo http://www.exemplo.com/...imagem.jpg e .gif

F

http://pt.w3support.net/index.php?db=so&id=505922
by google

Criado 24 de novembro de 2010
Ultima resposta 24 de nov. de 2010
Respostas 2
Participantes 2