您现在的位置:首页 >> 前端 >> 内容

将整个html内容保存到指定文件

时间:2014/10/17 10:37:00 点击:

  核心提示:* 基本能实现网页抓取,不过要手动输入URL 将整个html内容保存到指定文件 **@author chenguoyong **/public class ScrubSelectedWeb { pri...

* 基本能实现网页抓取,不过要手动输入URL 将整个html内容保存到指定文件

*

*@author chenguoyong

*

*/

public class ScrubSelectedWeb {

privatefinal static String CRLF = System.getProperty("line.separator");

/**

* @param args

*/

publicstatic void main(String[] args) {

try{

URLur = newURL("https://www.google.cn/");

InputStreaminstr = ur.openStream();

Strings, str;

BufferedReaderin = new BufferedReader(new InputStreamReader(instr));

StringBuffersb = new StringBuffer();

BufferedWriterout = new BufferedWriter(new FileWriter(

"D:/outPut.txt"));

while((s = in.readLine()) != null) {

sb.append(s+ CRLF);

}

System.out.println(sb);

str= new String(sb);

out.write(str);

out.close();

in.close();

}catch (MalformedURLException e) {

e.printStackTrace();

}catch (IOException e) {

e.printStackTrace();

}

}

}



Tags:将整 整个 个H HT 
作者:网络 来源:不详