在主方法内写个method();就可以了
下面都直接复制过去可以用
private static void method() throws Exception
{
while (true)
{
try
{
Scanner urio=new Scanner(System.in);
System.out.print("CSDN某个人博客网址:");
String uri=urio.next();
URL url = new URL(uri);
BufferedReader read = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
String line ;
while ((line = read.readLine()) != null)
{
//将每次获得的数据继续一行处理
try
{
i = line.indexOf(uri + "/article/details/");
int io=line.indexOf(">");
int o=line.indexOf("</a>");
lne = line.substring(i, io);
lne2 = line.substring(io + 2, o);
}
catch (Exception e)
{
continue;
}
System.out.println("链接:" + lne.trim());
System.out.println("标题:" + lne2.trim());
Thread.sleep(100);
}
read.close();
System.out.println("结束运行!");
break;
}
catch (Exception e)
{
System.out.println("网址输入错误");
}
}
}