问题描述
比如这段程序实现了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;//起始IDint 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; }} 问题补充:<div class="quote_title">wanghuanqiu 写道</div><div class="quote_div">匹配关键字,输出title标签的内容</div><br /><br />谢谢,我现在是这样写的,直接只打印第四行(title在第四行)。<br /><pre name="code" class="java">while((tmp=br.readLine())!= null&&i<4)</pre>
解决方案
匹配关键字,输出title标签的内容