[問題] 搜尋字串的問題
各位先輩好
小弟目前有個程式碼是要抓取一個網頁的超連結數
也就是計算網頁裡的超連結數量
以下程式碼已可以成功地抓取網頁原始碼
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
→
03/14 19:27, , 1F
03/14 19:27, 1F
推
03/14 23:44, , 2F
03/14 23:44, 2F
→
03/14 23:45, , 3F
03/14 23:45, 3F