java获取网页主信息之五:测试

1.所需文件

 param.txt:存放需要提取信息的网页路径
 TestPage:存放需要提取信息的网页
 Out.txt:输出的网页内容

2.测试程序

  1. package test;   
  2.   
  3. import java.io.*;   
  4. import Source.*;   
  5.   
  6. //提取页面主要信息测试   
  7. public class ETest{   
  8.   
  9.     public static void main(String args[])   
  10.     {   
  11.         //输出文件   
  12.         String out = "out.txt";   
  13.         File outfile = new File(out);   
  14.         //建立html树   
  15.         HTML2Tree h2t = new HTML2Tree();   
  16.         String file = getFilename();   
  17.         h2t.main(file);   
  18.         HTree tree = h2t.getTree();   
  19.         //允许标准差   
  20.         double th = 0.79;   
  21.         //选择主要信息块   
  22.         ChooseBlock cb = new ChooseBlock(th);   
  23.         //输出主要信息   
  24.         String str = cb.getContent(tree);   
  25.         if(str == null)   
  26.         {   
  27.             System.out.println("文件为空");   
  28.             System.exit(1);   
  29.         }   
  30.         try  
  31.         {   
  32.             PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter(outfile)));   
  33.             p.println(str);   
  34.             p.close();   
  35.         }   
  36.         catch(IOException e)   
  37.         {   
  38.             System.out.println(e);   
  39.             System.exit(1);   
  40.         }   
  41.     }   
  42.     //获取要提取的网页文件名   
  43.     private static String getFilename()   
  44.     {   
  45.         String file = "";   
  46.         try  
  47.         {   
  48.             File f = new File("param.txt");   
  49.             BufferedReader fis = new BufferedReader(new FileReader(f));   
  50.             String s;   
  51.             while((s = fis.readLine()) != null)    
  52.             if(!s.equalsIgnoreCase(""))   
  53.             {   
  54.                  file = s;   
  55.                  break;   
  56.             }   
  57.         }   
  58.         catch(IOException e)   
  59.         {   
  60.             System.out.println(e);   
  61.             System.exit(1);   
  62.         }   
  63.         return file;   
  64.     }   
  65. }   

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值