Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/10/2008, 03:30
Belzebu
 
Fecha de Ingreso: enero-2007
Mensajes: 78
Antigüedad: 17 años, 4 meses
Puntos: 0
Respuesta: Extraer texto archivo HTML

He encontrado un contenido interesante sobre este tema en: http://www.exampledepot.com/egs/java...l/GetText.html

He modificado el texto a:

Código PHP:
import java.io.*;
import java.net.*;
import javax.swing.text.*;
import javax.swing.text.html.*;


class 
getText {
    public static 
void main(String[] args) {
        
    
String uriStr args[0];
    
String probando="";

        final 
StringBuffer buf = new StringBuffer(1000);
    
        try {
            
// Create an HTML document that appends all text to buf
            
HTMLDocument doc = new HTMLDocument() {
                public 
HTMLEditorKit.ParserCallback getReader(int pos) {
                    return new 
HTMLEditorKit.ParserCallback() {
                        
// This method is whenever text is encountered in the HTML file
                        
public void handleText(char[] dataint pos) {
                            
buf.append(data);
                            
buf.append('\n');
                        }
                    };
                }
            };
    
            
// Create a reader on the HTML content
            
URL url = new URI(uriStr).toURL();
            
URLConnection conn url.openConnection();
            
Reader rd = new InputStreamReader(conn.getInputStream());
    
            
// Parse the HTML
            
EditorKit kit = new HTMLEditorKit();
            
kit.read(rddoc0);
        } catch (
MalformedURLException e) {
        } catch (
URISyntaxException e) {
        } catch (
BadLocationException e) {
        } catch (
IOException e) {
        }
    
        
// Return the text
       
System.out.println(buf.toString());
    
    }


pero no consigo que el codigo realice su objetivo final(extraer el texto), a ver si alguien me puede hechar un cable.

Gracias