比如这段程序实现了Java打印“http://www.yeyar.com/TeamDetails.aspx?T=1”自T=1到10的HTML源代码,但我只想打印出来其中的title信息,怎么修改呢? import java.io.*;
import java.net.URL;
import java.net.URLConnection;
public class DownloadPage {
public static void main(String[] args) {
String pre = "http://www.yeyar.com/TeamDetails.aspx?T=";
String suf = "";
int start = 1;//起始ID
int len = 10;//连续的数量
for(int i=start; i<=start+len; i++){
try {
download(pre,i+"",suf);
} catch (Throwable e) {
System.out.println(e.getMessage());
}
}
}
public static Object download(String prefix,String special,String suffix) throws Throwable{
URL url = new URL(prefix+special+suffix);
URLConnection uc =url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String tmp = null;
System.out.println(url.toString());
// FileWriter fw = new FileWriter("C:\\Users\\Sun\\Desktop\\1234.txt");
while((tmp=br.readLine()) != null){
if(tmp.trim().isEmpty())continue;
System.out.println(tmp+"\n");
break; //这里只打印了一行,去点的话会全部打印。
}
// fw.close();
br.close();
return null;
}
}
添加回答
举报
0/150
提交
取消