作者Jowall (那墙)
看板java
标题[问题] 搜寻字串的问题
时间Mon Mar 14 19:08:11 2011
各位先辈好
小弟目前有个程式码是要抓取一个网页的超连结数
也就是计算网页里的超连结数量
以下程式码已可以成功地抓取网页原始码
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
1F:→ ickxlin:java.util.regex正规表示式 03/14 19:27
2F:推 slalala:土一点 indexOf equle contain 等等 我是觉得从基本开 03/14 23:44
3F:→ slalala:始摸索 比较好 03/14 23:45