一个简单的网页抓取例子(二)
public static void main(final String args[]) {
String url = "";
final List list = new ArrayList();
System.out.print("输入URL,一行一个,输入结束后输入 go 程序开始运行: \n");
final BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
try {
while (!(url = br.readLine()).equals("go")) // 如果输入不是go那么一直读取
{
list.add(url);
}
} catch (final Exception e) {
e.getMessage();
}
final WebContent wc = new WebContent();
HashMap> hashMap = new HashMap
>();
for (int i = 0; i < list.size(); i++) {
if (wc.getFromUrls(list.get(i)) != null) {
hashMap = wc.getFromUrls(list.get(i));
}
for (Iterator iter = hashMap.keySet().iterator(); iter
.hasNext();) {
String key = iter.next();
List list2 = hashMap.get(key);
System.out.println("--" + key + "内容如下:");
for (int j = 0; j < list2.size(); j++) {
System.out.println(list2.get(j));
}
}
}
}
}