Witam,

mam problem z tagiem HTML . Kiedy uruchamiam program taki jak poniżej otrzymuję bez problemu listę atrybutów CLASS dla tego tagu. Kiedy jednak zamienię

na nie otrzymuję żadnych wyników. Ktoś ma pomysł dlaczego tak się może dziać?</p>

Pozdrawiam,

Paweł

import javax.swing.text.html.*;
import javax.swing.text.Element;
import javax.swing.text.ElementIterator;
import java.net.URL;
import java.io.InputStreamReader;
import java.io.Reader;


public class HTMLParser
{
  public static void main( String[] argv ) throws Exception
  {
    URL url = new URL( "http://cnn.com" ); 
    HTMLEditorKit kit = new HTMLEditorKit(); 
    HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument(); 
    doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
    Reader HTMLReader = new InputStreamReader(url.openConnection().getInputStream()); 
    kit.read(HTMLReader, doc, 0); 

    ElementIterator it = new ElementIterator(doc); 
    Element elem; 
    
    while( (elem = it.next()) != null  )
    { 
      if( elem.getName().equals(HTML.Tag.DIV.toString()) )
      { 
        String s = (String) elem.getAttributes().getAttribute(HTML.Attribute.CLASS);
        if( s != null ) 
          System.out.println (s);
      } 
    }
    System.exit(0);
  }