首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

施用web-harvest抓取分页数据(二)

2012-11-07 
使用web-harvest抓取分页数据(二)除了使用上述方法外,还可以使用将不页的数据输出到不同的结构化好的XML文

使用web-harvest抓取分页数据(二)
   除了使用上述方法外,还可以使用将不页的数据输出到不同的结构化好的XML文件里面,

然后再进行读取的方法:

    配置文件:

   

        

   接着是JAVA文件里面的关键代码:

   
public void QueryPath(int num) {   try{    ScraperConfiguration config = new ScraperConfiguration("traveldata/config/hotel.xml");        Scraper scraper = new Scraper(config, "traveldata/output/hotel");                scraper.addVariableToContext("page_num", new String(""+num));             scraper.setDebug(true);        long starttime = System.currentTimeMillis();        scraper.execute();        long endtime = System.currentTimeMillis();        System.out.println("Spent time:"+(endtime - starttime));                  saveHotel(num);           }   catch(Exception e)   {   e.printStackTrace();   }}  public void getContent(int pageNum)  //循环调用{for(int i=1;i<=pageNum;i++){QueryPath(i);}}
1 楼 zzhzzh204553 2008-11-01   这些循环操作,可以全部写在XML文件中。
不然又要写java代码,又要考虑xml文件

热点排行