import java.net.URL; import java.io.*; import javax.swing.text.BadLocationException; import javax.swing.text.html.HTML; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLEditorKit; public class Fetkoll { //Hitta och skriv ut det som är skrivet med fetstil public static String läsURL(String webpage)throws IOException { StringBuilder temp=new StringBuilder(); //String webpage="http://www.nada.kth.se/~henrik"; InputStream in=new URL(webpage).openConnection().getInputStream(); InputStreamReader reader= new InputStreamReader(in); while(reader.ready()) temp.append((char)reader.read()); return temp.toString(); } public static boolean btag(String text,int startindex,int endindex){ boolean foundB=false; startindex++; while (startindex'){ return startindex; } startindex++; } return -1; } public static void main(String[] args) { // TODO Auto-generated method stub try{ String url="http://www.nada.kth.se/~marko/ovningar/prutt16/Ovning6/test.html"; //String innehåll = läsURL(url); //fetskrivare(innehåll); boldwriter(url); //System.out.println(innehåll); } catch(IOException e){ System.out.println("läsfel"); } } public static void boldwriter(String url)throws IOException{ HTMLDocument doc=new HTMLDocument(); HTMLEditorKit läs; InputStream in=new URL(url).openConnection().getInputStream(); InputStreamReader reader= new InputStreamReader(in); läs = new HTMLEditorKit(); try{ läs.read(reader, doc, 0); HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.B); while (it.isValid()){ int start=it.getStartOffset(); int length=it.getEndOffset()-start; System.out.println(doc.getText(start, length)); it.next(); } } catch(BadLocationException e){ throw new IOException(); } } }