在创建一个job后,就要开始job的运行,运行的全流程如下:

1、在界面上启动job

2、index.jsp

查看上述页面对应的源代码

<a href='"+request.getContextPath()+"/console/action.jsp?action=start'>Start</a>

3、action.jsp

    String sAction = request.getParameter("action");if(sAction != null){// Need to handle an action    if(sAction.equalsIgnoreCase("start")){// Tell handler to start crawl jobhandler.startCrawler();} else if(sAction.equalsIgnoreCase("stop")) {// Tell handler to stop crawl jobhandler.stopCrawler();} else if(sAction.equalsIgnoreCase("terminate")) {// Delete current jobif(handler.getCurrentJob()!=null){handler.deleteJob(handler.getCurrentJob().getUID());}} else if(sAction.equalsIgnoreCase("pause")) {// Tell handler to pause crawl jobhandler.pauseJob();} else if(sAction.equalsIgnoreCase("resume")) {// Tell handler to resume crawl jobhandler.resumeJob();} else if(sAction.equalsIgnoreCase("checkpoint")) {if(handler.getCurrentJob() != null) {handler.checkpointJob();}}}    response.sendRedirect(request.getContextPath() + "/index.jsp");

4、CrawlJobHandler.jsp

(1)

    public void startCrawler() {running = true;if (pendingCrawlJobs.size() > 0 && isCrawling() == false) {// Ok, can just start the next jobstartNextJob();}}

(2)

    protected final void startNextJob() {synchronized (this) {if(startingNextJob != null) {try {startingNextJob.join();} catch (InterruptedException e) {e.printStackTrace();return;}}startingNextJob = new Thread(new Runnable() {public void run() {startNextJobInternal();}}, "StartNextJob");startingNextJob.start();}}

(3)

   protected void startNextJobInternal() {if (pendingCrawlJobs.size() == 0 || isCrawling()) {// No job ready or already crawling.return;}this.currentJob = (CrawlJob)pendingCrawlJobs.first();assert pendingCrawlJobs.contains(currentJob) :"pendingCrawlJobs is in an illegal state";pendingCrawlJobs.remove(currentJob);try {this.currentJob.setupForCrawlStart();// This is ugly but needed so I can clear the currentJob// reference in the crawlEnding and update the list of completed// jobs.  Also, crawlEnded can startup next job.this.currentJob.getController().addCrawlStatusListener(this);// now, actually startthis.currentJob.getController().requestCrawlStart();} catch (InitializationException e) {loadJob(getStateJobFile(this.currentJob.getDirectory()));this.currentJob = null;startNextJobInternal(); // Load the next job if there is one.}}

(4)

    public void requestCrawlStart() {runProcessorInitialTasks();sendCrawlStateChangeEvent(STARTED, CrawlJob.STATUS_PENDING);String jobState;state = RUNNING;jobState = CrawlJob.STATUS_RUNNING;sendCrawlStateChangeEvent(this.state, jobState);// A proper exit will change this value.this.sExit = CrawlJob.STATUS_FINISHED_ABNORMAL;Thread statLogger = new Thread(statistics);statLogger.setName("StatLogger");statLogger.start();frontier.start();}

【Heritrix基础教程之4】开始一个爬虫抓取的全流程代码分析相关推荐

  1. 用爬虫抓取美联储演讲数据并分析金融政策

    用python抓取美联储数据 近日,笔者选择了一个任务,用爬虫抓取美联储演讲数据,并分析相关金融政策. 首先必须做的,是抓取数据. 打开美联储的网站Federal Reserve Board - Ho ...

  2. 【Heritrix基础教程之1】在Eclipse中配置Heritrix

    一.新建项目并将Heritrix源码导入 1.下载heritrix-1.14.4-src.zip和heritrix-1.14.4.zip两个压缩包,并解压,以后分别简称SRC包和ZIP包: 2.在Ec ...

  3. 【Heritrix基础教程之3】Heritrix的基本架构

    Heritrix可分为四大模块: 1.控制器CrawlController 2.待处理的uri列表  Frontier 3.线程池 ToeThread 4.各个步骤的处理器 (1)Pre-fetch ...

  4. Python爬虫抓取指定网页图片代码实例

    更多编程教程请到:菜鸟教程 https://www.piaodoo.com/ 友情链接:好看站 http://www.nrso.net/ 高州阳光论坛https://www.hnthzk.com/ 想 ...

  5. 【Heritrix基础教程之2】Heritrix基本内容介绍

    1.版本说明 (1)最新版本:3.3.0 (2)最新release版本:3.2.0 (3)重要历史版本:1.14.4 3.1.0及之前的版本:http://sourceforge.net/projec ...

  6. python可以处理多大的数据_科多大数据之Python基础教程之Excel处理库openpyxl详解...

    原标题:科多大数据之Python基础教程之Excel处理库openpyxl详解 科多大数据小课堂来啦~Python基础教程之Excel处理库openpyxl详解 openpyxl是一个第三方库,可以处 ...

  7. python的excell库_扣丁学堂Python基础教程之Excel处理库openpyxl详解

    扣丁学堂Python基础教程之Excel处理库openpyxl详解 2018-05-04 09:49:49 3197浏览 openpyxl是一个第三方库,可以处理xlsx格式的Excel文件.pipi ...

  8. pgsql数据库默认配置事务类型_PostgreSQL基础教程之:初始化配置

    PostgreSQL基础教程之:初始化配置 时间:2020-04-27 来源: PostgreSQL基础教程之:初始化配置 一.配置pg_hba.conf 先说明客户端认证配置文件pg_hba.con ...

  9. Linux入门基础教程之Linux下软件安装

    Linux入门基础教程之Linux下软件安装 一.在线安装: sudo apt-get install 即可安装 如果在安装完后无法用Tab键补全命令,可以执行: source ~/.zshrc AP ...

最新文章

  1. python3.7如何使用enum_我如何用Python表示‘Enum’?
  2. 实用的人工智能 但数据 Python 速查表
  3. 20.Android studio提示Cmake Error executing external native build for cmake...
  4. epoll_data_t里面的void *ptr; int fd; u32; u64 分析
  5. [TCP/IP] TCP在listen时的参数backlog的意义
  6. 使用DistroTweaks复制您的自定义Linux设置
  7. 敏捷开发你必须知道的7件事
  8. 【Kafka】kafka方式消息不丢失的一些参数设置
  9. c 取数组 最大值 算法_拜托,面试别再问我最大值最小值了!!!
  10. Python学习之路day3-集合
  11. css compressor java_使用YUI Compressor压缩CSS/JS
  12. matlab画图基本命令
  13. Awvs 12.x安装及使用教程
  14. mysql截取身份证号前几位_EXCEL中怎样截取身份证号前六位数字
  15. Windows10 添加开始菜单未显示应用到磁贴的方法
  16. 绘制网络组建拓扑图方法分享
  17. Spring学习(二)IOC
  18. 17、springcloud整合lettuce使用redis
  19. Linux系统cp:omitting directory`XXX'问题解决
  20. RHCE第一讲【II】

热门文章

  1. 26行代码AC——习题3-2 分子量 (UVa1586,Molar Mass)——解题报告
  2. 数据结构题:由逆置数组方法——逆置线性表L的所有元素
  3. python类与函数编程_Python类三种方法,函数传参,类与实例变量(一)详解
  4. json python无效语法_在python中打开无效的json文件
  5. LVM逻辑卷 (概述lvm,管理卷组 物理卷 逻辑卷,磁盘配额)
  6. 程序员应该知道的二十三种设计模式
  7. python语法错误怎么办_Python中“函数外返回”语法错误的原因?
  8. 分页offset格式_Thinkphp5 原生sql分页操作
  9. fastdfs redis java,大文件上传_断点续传_文件分片传输_fastdfs_前后端一站式解决方案...
  10. php面试带项目_PHP面试常用算法(推荐)