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

package parser;

 

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.net.MalformedURLException;

import java.net.URL;

 

/**

 * 基本能实现网页抓取,不过要手动输入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("http://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();

              }

 

       }

 

}

http://c.tieba.baidu.com/p/3389457489
http://c.tieba.baidu.com/p/3389466826
http://c.tieba.baidu.com/p/3389470640
http://c.tieba.baidu.com/p/3389472377
http://c.tieba.baidu.com/p/3389473930
http://c.tieba.baidu.com/p/3389477136
http://c.tieba.baidu.com/p/3389475148
http://c.tieba.baidu.com/p/3389485599
http://c.tieba.baidu.com/p/3389513216
http://c.tieba.baidu.com/p/3389517509
http://c.tieba.baidu.com/p/3389520313
http://c.tieba.baidu.com/p/3389522398
http://c.tieba.baidu.com/p/3390769932
http://c.tieba.baidu.com/p/3392021705
http://c.tieba.baidu.com/p/3392323863
http://c.tieba.baidu.com/p/3392330792
http://c.tieba.baidu.com/p/3392336731
http://c.tieba.baidu.com/p/3392342524
http://c.tieba.baidu.com/p/3392347298
http://c.tieba.baidu.com/p/3375675193
http://c.tieba.baidu.com/p/3375686025
http://c.tieba.baidu.com/p/3375690552
http://c.tieba.baidu.com/p/3375695670
http://c.tieba.baidu.com/p/3375701076
http://c.tieba.baidu.com/p/3375709000
http://c.tieba.baidu.com/p/3375716663
http://c.tieba.baidu.com/p/3375740498
http://c.tieba.baidu.com/p/3375749024
http://c.tieba.baidu.com/p/3375766133
http://c.tieba.baidu.com/p/3392359946
http://c.tieba.baidu.com/p/3387737417
http://c.tieba.baidu.com/p/3387738658
http://c.tieba.baidu.com/p/3387739838
http://c.tieba.baidu.com/p/3387783818
http://c.tieba.baidu.com/p/3387786470
http://c.tieba.baidu.com/p/3387783818
http://c.tieba.baidu.com/p/3382021222
http://c.tieba.baidu.com/p/3382021222
http://c.tieba.baidu.com/p/3382009487
http://c.tieba.baidu.com/p/3382005675
http://c.tieba.baidu.com/p/3382002991
http://c.tieba.baidu.com/p/3381994737
http://c.tieba.baidu.com/p/3381991852
http://c.tieba.baidu.com/p/3381988322
http://c.tieba.baidu.com/p/3381986298
http://c.tieba.baidu.com/p/3381983852
http://c.tieba.baidu.com/p/3381981736
http://c.tieba.baidu.com/p/3381979917
http://c.tieba.baidu.com/p/3381918554
http://c.tieba.baidu.com/p/3381918127
http://c.tieba.baidu.com/p/3381914696
http://c.tieba.baidu.com/p/3381913501
http://c.tieba.baidu.com/p/3381913187
http://c.tieba.baidu.com/p/3381911905
http://c.tieba.baidu.com/p/3381911406
http://c.tieba.baidu.com/p/3381910239
http://c.tieba.baidu.com/p/3381909751
http://c.tieba.baidu.com/p/3381905367
http://c.tieba.baidu.com/p/3381903236
http://c.tieba.baidu.com/p/3381892748
http://c.tieba.baidu.com/p/3387734920
http://c.tieba.baidu.com/p/3387734170
http://c.tieba.baidu.com/p/3387733127
http://c.tieba.baidu.com/p/3387732611
http://c.tieba.baidu.com/p/3387732170
http://c.tieba.baidu.com/p/3387731630
http://c.tieba.baidu.com/p/3387731086
http://c.tieba.baidu.com/p/3387730892
http://c.tieba.baidu.com/p/3387728964
http://c.tieba.baidu.com/p/3387725536
http://c.tieba.baidu.com/p/3374352634
http://c.tieba.baidu.com/p/3374351958
http://c.tieba.baidu.com/p/3374351507
http://c.tieba.baidu.com/p/3374350912
http://c.tieba.baidu.com/p/3374349860
http://c.tieba.baidu.com/p/3374344211
http://c.tieba.baidu.com/p/3374341531
http://c.tieba.baidu.com/p/3374339288
http://c.tieba.baidu.com/p/3374338595
http://c.tieba.baidu.com/p/3374337825
http://c.tieba.baidu.com/p/3374336667
http://c.tieba.baidu.com/p/3374334686
http://c.tieba.baidu.com/p/3374333843
http://c.tieba.baidu.com/p/3374333168
http://c.tieba.baidu.com/p/3392384335
http://c.tieba.baidu.com/p/3392396252

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。