📄 reptile.java
字号:
/*
* FileName Main.java
* Create Time 2005-8-11 14:27:00
* Author shiwei
* Descript 启动reptile
* Version
*/
package com.snoics.reptile.main;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import com.snoics.base.interfaces.log.Log;
import com.snoics.reptile.cache.Cache;
import com.snoics.reptile.cache.ICache;
import com.snoics.reptile.cache.TempCache;
import com.snoics.reptile.parse.IParseFile;
import com.snoics.reptile.parse.ParseHtml;
import com.snoics.reptile.system.common.Common;
import com.snoics.reptile.system.common.CommonObject;
import com.snoics.useclass.SnoicsClass;
public class Reptile {
private CommonObject commonObject=new CommonObject();
private Log log=null;
private SnoicsClass snocisClass=new SnoicsClass();
public Reptile(){
log=snocisClass.getLog();
log.getLogger("com.snoics.reptile");
}
/**
* 开始抓取网站
*/
public void parse(){
String website=commonObject.getConfigInfo(Common.CONFIGFILE_NODE_WEBSITE);
String startPageUrl=commonObject.getConfigInfo(Common.CONFIGFILE_NODE_STARTPAGE);
log.info("开始抓取站点: "+website);
IParseFile parse=new ParseHtml();
parse.parseAll(startPageUrl,null);
Cache cache=new Cache();
ArrayList reptilecache=commonObject.getReptileCache();
cache.setCache(reptilecache);
//cache.save();
ICache tempCache=new TempCache();
ArrayList reptiletempcache=commonObject.getReptileTempCache();
cache.setCache(reptiletempcache);
cache.save();
cache.clearCacheMemory();
tempCache.setCache(reptiletempcache);
tempCache.clearCacheMemory();
log.info("本次一共抓取的页面数为: "+Common.createHtmlFileCount);
log.info("本次一共抓取的文件数为: "+Common.createBinfFileCount);
log.info("站点抓取完成!");
}
/**
* 打印系统配置信息
*
*/
public void configInfo(){
String website=commonObject.getConfigInfo(Common.CONFIGFILE_NODE_WEBSITE);
String websitename=commonObject.getConfigInfo(Common.CONFIGFILE_NODE_WEBSITENAME);
String startPage=commonObject.getConfigInfo(Common.CONFIGFILE_NODE_STARTPAGE);
String url=commonObject.getConfigInfo(Common.CONFIGFILE_NODE_URL);
String forbidurl=commonObject.getConfigInfo(Common.CONFIGFILE_FORBIDURL);
String cachefile=commonObject.getConfigInfo(Common.CONFIGFILE_NODE_CACHEFILE);
String cacheunitsize=commonObject.getConfigInfo(Common.CONFIGFILE_NODE_CACHEUNITSIZE);
String filerootpath=commonObject.getConfigInfo(Common.CONFIGFILE_NODE_FILEROOTPATH);
String filenamelength=commonObject.getConfigInfo(Common.CONFIGFILE_NODE_FILENAMELENGTH);
String undownloadfiletype=commonObject.getConfigInfo(Common.DEFAULT_UNDOWNLOADFILETYPE);
String downloadfiletype=commonObject.getConfigInfo(Common.DEFAULT_DOWNLOADFILETYPE);
log.info("------------------------------------------------");
log.info("将要抓取的站点: "+website);
log.info("站点名称: "+websitename);
log.info("起始页面: "+startPage);
log.info("需要抓取的部分为: "+url);
log.info("不抓取的部分为: "+forbidurl);
log.info("文件保存路径为: "+filerootpath);
log.info("HTML文件名长度为: "+filenamelength);
log.info("二进制文件类型: "+undownloadfiletype);
log.info("将被下载到本地的文件类型: "+downloadfiletype);
log.info("Cache文件: "+cachefile);
log.info("一个Cache单元的大小: "+cacheunitsize);
log.info("------------------------------------------------");
}
/**
* 确定是否开始(普通应用程序使用)
* @return boolean
*/
public boolean confirm(){
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
log.info("是否要开始抓取?(y/n)");
String inputstring="";
try{
inputstring=bufferedReader.readLine();
}catch(Exception e){
}
inputstring=inputstring.trim().toUpperCase();
if(inputstring.equals("Y")){
return true;
}else{
return false;
}
}
/**
* 摧毁对象池中的对象
*/
public void destorySysmteObject(){
commonObject.destorySystemObject();
}
/**
* 彻底摧毁对象池中的所有对象
*
*/
public void clearSystem(){
commonObject.clearSystem();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -