JSpider.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:1k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider;
  2. import net.javacoding.jspider.core.*;
  3. import net.javacoding.jspider.core.impl.CLI;
  4. import net.javacoding.jspider.core.util.config.ConfigurationFactory;
  5. import java.net.URL;
  6. /**
  7.  * Main startup class.
  8.  *
  9.  * $Id: JSpider.java,v 1.27 2003/04/10 16:19:03 vanrogu Exp $
  10.  *
  11.  * @author G黱ther Van Roey
  12.  * @todo support commandline input for proxy password
  13.  * @todo implement Swing-based monitor UI ( threading, progress, ...)
  14.  */
  15. public class JSpider {
  16.     protected Spider spider;
  17.     protected SpiderContext context;
  18.     public JSpider ( URL baseURL ) throws Exception {
  19.         SpiderNest nest = new SpiderNest();
  20.         context = SpiderContextFactory.createContext(baseURL);
  21.         spider = nest.breedSpider(context);
  22.     }
  23.     public void start ( ) throws Exception {
  24.         spider.crawl(context);
  25.     }
  26.     public SpiderContext getContext() {
  27.         return context;
  28.     }
  29.     public static void main(String[] args) throws Exception {
  30.         CLI.printSignature();
  31.         if (args.length != 1 && args.length != 2 ) {
  32.             System.out.println("Usage: JSpider baseURL [config]");
  33.             return;
  34.         }
  35.         if (args.length > 1) {
  36.             ConfigurationFactory.getConfiguration(args[1]);
  37.         } else {
  38.             ConfigurationFactory.getConfiguration();
  39.         }
  40.         URL baseURL = new URL(args[0]);
  41.         JSpider jspider = new JSpider ( baseURL );
  42.         jspider.start ( );
  43.     }
  44. }