Ler HTML de site com JAVA

2 respostas
surfzera

Pessoal como faço para ler um site HTML e extrair seus dados. ??? algum exemplo ?

2 Respostas

dyorgio

Para a conexão HTTP use a lib da apache httpclient-4.0

para o parser tu podes usar o http://htmlparser.sourceforge.net/

ctdaa

Para ler o html vc pode usar algo assim:

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;

public class Test {

   public static void main(String[] args) {

      try {
          URL url = new URL("http://endereco-do-site/Index.htm");
          URI uri = url.toURI();
          BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
          String s;
          while ((s = br.readLine()) != null) {
                System.out.println(s);
          }
          br.close();
      } catch (MalformedURLException excecao) {
          excecao.printStackTrace();
      } catch (URISyntaxException excecao) {
          excecao.printStackTrace();
      } catch (IOException excecao) {
          excecao.printStackTrace();
      }

}
Criado 19 de março de 2010
Ultima resposta 19 de mar. de 2010
Respostas 2
Participantes 3