Package barrysoft.web

Examples of barrysoft.web.Parser


                      "[city] is the capital of [country]\\s"+
                      "The native name of [country] is (.+?)$";
  @Test
  public void testParse() {
   
    Parser p = new Parser("Test Parser");
    /*p.addRule(parseRule);
    p.addRuleParam(parseRule, p.new ParserRuleParam("city", "Rome"));
    p.addRuleParam(parseRule, p.new ParserRuleParam("country", "Italy"));*/
   
    ParserRule pr = new ParserRule(parseRule);
    pr.addParam(new ParserRuleParam("city", "Rome"));
    pr.addParam(new ParserRuleParam("country", "Italy"));
   
    p.addRule(pr);
     
    p.parseData(plainData);
   
    String[][] results = p.getRule(0).getResults();
    checkResults(results, 1, new int[] {2});
   
    assertEquals("Wrong group data.", "Roma", results[0][0]);
    assertEquals("Wrong group data.", "Italia", results[0][1]);
   
View Full Code Here


  public final static String timeRule = "(?i)(?s).*The current time.*?(\\d+[.:]+\\d\\d *[AP]*M*).*";
 
  @Test
  public void testParseURL() {
   
    Parser p = new Parser("Time Parser");
    p.addRule(new ParserRule(timeRule));
   
    try {
     
      p.parseData(new WebDownloader(timeURL));
     
      String[][] results = p.getRule(0).getResults();
     
      checkResults(results, 1, new int[] {1});

      System.out.println(results[0][0]);
     
View Full Code Here

  };
 
  @Test
  public void testParserITSA() {
   
    Parser p = new Parser("ITSA Parser");
   
    ParserRuleParam prp = new ParserRuleParam("series");
   
    for (String s : series)
      prp.addValue(s);
   
    ParserRule pr = new ParserRule(itsaRule, prp);
    pr.setQuickRule(" [series]<");
   
    p.addRule(pr);
   
    try {
     
      WebDownloader wd = new WebDownloader("http://www.italiansubs.net/index.php");
      wd.addFormElement("option", "com_remository");
     
      p.parseData(wd);

      String[][] results = p.getRule(0).getResults();
     
      int[] expected = new int[series.length];
      Arrays.fill(expected, 1);
     
      checkResults(results, series.length, expected);
View Full Code Here

  };
 
  @Test
  public void testParserMultipleRules() {
   
    Parser p = new Parser("ITSA Parser Multi");
   
    for (String rule : multipleRules)
      p.addRule(new ParserRule(rule));
   
    try {
     
      WebDownloader wd = new WebDownloader("http://www.italiansubs.net/index.php");
      wd.addFormElement("option", "com_remository");
      wd.addFormElement("func", "fileinfo");
      wd.addFormElement("id", "2126");
     
      p.parseData(wd);

      for (int i=0; i < multipleRules.length; i++) {
        String[][] results = p.getRule(i).getResults();
       
        checkResults(results, 1, new int[] {1});
       
        System.out.println(results[0][0].trim());
      }
View Full Code Here

  };
 
  @Test
  public void testParserMultipleParamsRules() {
   
    Parser p = new Parser("ITSA Parser Multi");
   
    for (String rule : multipleParamsRules)
      p.addRule(new ParserRule(rule));
   
    ParserRule pr = p.getRule(multipleParamsRules.length-1);
    pr.addParam(new ParserRuleParam("tag", "Inviato il "));
   
    try {
     
      pr.getParam("tag").addValue("Dimensioni del file: ");
     
      WebDownloader wd = new WebDownloader("http://www.italiansubs.net/index.php");
      wd.addFormElement("option", "com_remository");
      wd.addFormElement("func", "fileinfo");
      wd.addFormElement("id", "2126");
     
      p.parseData(wd);
     
      String[][] results = p.getRule(0).getResults();
      checkResults(results, 1, new int[] {1});
      System.out.println(results[0][0]);
     
      results = p.getRule(1).getResults();
      checkResults(results, 2, new int[] {1, 1});
     
      for(String[] s : results)
        System.out.println(s[0].trim());
     
View Full Code Here

  }
 
  @Test
  public void testSave() {
   
    Parser p = new Parser("Save Parser");
   
    for (String rule : regexs) {
      ParserRule pr = new ParserRule(rule);
     
      for (int i=0; i < 3; i++) {
       
        ParserRuleParam prp = new ParserRuleParam("param"+(i+1));
       
        for (int j=0; j < 5; j++)
          prp.addValue("value"+(j+1));
       
        pr.addParam(prp);
       
      }
     
      pr.setGroupName("group1", 0);
      pr.setGroupName("group2", 1);
     
      p.addRule(pr);
    }
   
    String xmlSource = p.getXML(0);
   
    System.out.println(xmlSource);
   
    InputSource is = new InputSource(new StringReader(xmlSource));
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;
   
    try {
      db = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e1) {
      fail(e1.getMessage());
    }
   
    Document doc = null;
    try {
      doc = db.parse(is);
    } catch (SAXException e) {
      fail(e.getMessage());
    } catch (IOException e) {
      fail(e.getMessage());
    }
   
    Parser p2 = new Parser();
    p2.loadFromXML(doc.getFirstChild());
   
    assertEquals(p2.getRulesCount(), regexs.length);
   
    for (int i=0; i < p2.getRulesCount(); i++) {
     
      ParserRule pr = p2.getRule(i);
     
      assertEquals(pr.getRule(), regexs[i]);
      assertEquals(3, pr.getParamsCount());
     
      for (int j=0; j < pr.getParamsCount(); j++) {
View Full Code Here

 
  public static final String tvstRegex = "<span style=\"[^\"]*\"><b>(\\w+)\\s*subtitles</b></span></div>\\s*<a href=\"([^\"]*)\">";
 
  public void testMultipleResults() {
   
    Parser p = new Parser("TVSubtitles.net Parser");
    ParserRule rule = new ParserRule(tvstRegex);
    rule.setGroupName("Language", 0);
    rule.setGroupName("Link", 1);
   
    p.addRule(rule);
   
    WebDownloader dl = new WebDownloader();
    try {
      dl.setUrl("http://www.tvsubtitles.net/episode-3079.html");
    } catch (MalformedURLException e) {
      fail(e.getMessage());
    }
   
    try {
      p.parseData(dl);
    } catch (IllegalStateException e) {
      fail(e.getMessage());
    } catch (IOException e) {
      fail(e.getMessage());
    }
View Full Code Here

TOP

Related Classes of barrysoft.web.Parser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.