看板 java 關於我們 聯絡資訊
各位先輩好 小弟目前有個程式碼是要抓取一個網頁的超連結數 也就是計算網頁裡的超連結數量 以下程式碼已可以成功地抓取網頁原始碼 import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.MalformedURLException; import java.net.URL; public class SourceViewer { public static void main(String[] args) { if (args.length > 0) { try { // open the URL for reading URL u = new URL(args[0]); InputStream in = u.openStream(); // buffer the input by chaining to increase performance in = new BufferedInputStream(in); // chaining the InputStream to a Reader Reader r = new InputStreamReader(in); int c; while ((c = r.read()) != -1) { // print out the html file on screen System.out.print((char) c); } } catch (MalformedURLException ex) { System.err.println(args[0] + " is not a parseable URL"); } catch (IOException ex) { System.err.println(ex); } } // end if } // end main } // end SourceViewer 那如果要從我讀進來的原始檔中搜尋超連結並計算數目,需要用到哪個class? 一點頭緒都沒有,請前輩們指教。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.144.128
ickxlin:java.util.regex正規表示式 03/14 19:27
slalala:土一點 indexOf equle contain 等等 我是覺得從基本開 03/14 23:44
slalala:始摸索 比較好 03/14 23:45