Java で基本的な Web クローラーを作成するためのチュートリアルに従い、基本的な機能を備えたものを手に入れました。
現時点では、サイトから HTML を取得してコンソールに出力するだけです。HTMLページのタイトルやHTTPステータスコードなどの詳細を除外できるように拡張したいと思っていましたか?
私はこのライブラリを見つけました:http: //htmlparser.sourceforge.net/ ...これで仕事ができると思いますが、外部ライブラリを使用せずにそれを行うことができますか?
これが私がこれまでに持っているものです:
public static void main(String[] args) {
// String representing the URL
String input = "";
// Check if argument added at command line
if (args.length >= 1) {
input = args[0];
}
// If no argument at command line use default
else {
input = "http://www.my_site.com/";
System.out.println("\nNo argument entered so default of " + input
+ " used: \n");
}
// input test URL and read from file input stream
try {
testURL = new URL(input);
BufferedReader reader = new BufferedReader(new InputStreamReader(
testURL.openStream()));
// String variable to hold the returned content
String line = "";
// print content to console until no new lines of content
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("Exception thrown");
}
}