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!"); } } }
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()); }
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); }