コード例 #1
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());
  }
コード例 #2
0
  public Variable execute(Scraper scraper, ScraperContext context) {
    Variable body = getBodyTextContent(templateDef, scraper, context);

    String language = BaseTemplater.execute(templateDef.getLanguage(), scraper.getScriptEngine());
    if (language != null) {
      language = language.toLowerCase();
    }
    ScriptEngine scriptEngine =
        language == null ? scraper.getScriptEngine() : scraper.getScriptEngine(language);

    String result = BaseTemplater.execute(body.toString(), scriptEngine);

    return new NodeVariable(result);
  }
コード例 #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);
  }