前景提要:如何开发一个新闻订阅APP之爬虫篇(一、背景介绍&需求分析)
做一个特定的爬虫系统,首先考虑它要做什么?
从互联网上抓取指定的N个站点信息,解析提取需要的内容,按照特定的结构存储;
系统结构图如下:
下面是主要的代码结构;
首先,定义一个CrawlerBootStrap类,作为整个系统的主入口。
public void init(){
crawlerList = new ArrayList <Crawler >() ;
for( String name : crawlerNameList ){
Crawler c = (Crawler ) SpringUtil. getObject( name) ;
if( c. init())
crawlerList .add (c );
}
start() ;
}
//爬虫线程池,存储多个爬虫,控制同一时间正在运行爬虫个数
public void start(){
//爬虫池
int corePoolSize = 20 ;
int maximumPoolSize = 1000 ;
long keepAliveTime = 100000L ;
BlockingQueue <Runnable > runnableTaskQueue = new PriorityBlockingQueue <Runnable >( 20) ;
ThreadPoolExecutor threadPoolExecutor = new