Exemplo n.º 1
0
  public void execute() {
    long startTime = System.currentTimeMillis();

    execute(configuration.getOperations());

    if (this.status == STATUS_RUNNING) {
      this.setStatus(STATUS_FINISHED);
    }

    // inform al listeners that execution is finished
    Iterator listenersIterator = this.scraperRuntimeListeners.iterator();
    while (listenersIterator.hasNext()) {
      ScraperRuntimeListener listener = (ScraperRuntimeListener) listenersIterator.next();
      listener.onExecutionEnd(this);
    }

    if (logger.isInfoEnabled()) {
      if (this.status == STATUS_FINISHED) {
        logger.info(
            "Configuration executed in " + (System.currentTimeMillis() - startTime) + "ms.");
      } else if (this.status == STATUS_STOPPED) {
        logger.info("Configuration stopped!");
      }
    }
  }
Exemplo n.º 2
0
  public void xinqiang1() throws FileNotFoundException {

    ScraperConfiguration config = new ScraperConfiguration("src/xinqiang/xinqiang1.xml");
    Scraper scraper = new Scraper(config, "d:/wh/work/");
    scraper.setDebug(true);
    scraper.execute();
    Variable r1 = scraper.getContext().getVar("targetPage");
    System.out.println(r1.toString());
  }
Exemplo n.º 3
0
  public String chongqing2() throws FileNotFoundException {
    ScraperConfiguration config = new ScraperConfiguration("src/chongqing/chongqing2.xml");
    Scraper scraper = new Scraper(config, "d:/wh/work/");
    scraper.setDebug(true);
    scraper.execute();
    //		Variable r1 = scraper.getContext().getVar("targetPage");
    //		System.out.println(r1.toString());
    //		System.out.println("----------------");
    Variable catalog = scraper.getContext().getVar("catalog");
    //		System.out.println(catalog);
    //		System.out.println("===========");
    String s = catalog.toString().replaceAll("<result>", ",{").replaceAll("</result>", "}");
    System.out.println("[" + s.substring(1) + "]");
    return "[" + s.substring(1) + "]";
    //		System.out.println(catalog.toList());
    //		List list = catalog.toList();
    //		for (Object s :list) {
    //			Map<String,Object> m = (Map<String, Object>) s;
    //			System.out.println("-->"+m.get("qs"));
    //		}

    //		Variable result = scraper.getContext().getVar("result");
    //		System.out.println(result);
  }