My simplest java fragment for screen-scraping !

[email protected] (Davide Grandi) Tue, 30 Jan 2007 21:33:25 +0100
Newsgroups gmane.comp.java.tn5250j.general
Message-ID <1hsrvej.znwh551cy6ty2N%[email protected]>
Thanks to the tracing of Web5250 I wrote my first and smallest screen
scraper with th5250j :

    ProtocolBean pb = new ProtocolBean("test", "123");
    pb.setHostName("10.10.10.1");
    Session5250 session = pb.getSession();
    pb.connect();
    while (!session.isConnected())
      Thread.sleep(500L);
    Screen5250 screen = session.getScreen();
    ScreenFields campi = screen.getScreenFields();
    ScreenField campoUtente = campi.findByPosition(3, 21);
    campoUtente.setString("DEMO");
    ScreenField campoPassword = campi.findByPosition(3, 46);
    campoPassword.setString("DEMO");
    screen.gotoField(campoUtente.getCurrentPos());
    screen.sendKeys("[enter]");
    while (screen.getOIA().getInputInhibited() == 1
        && screen.getOIA().getLevel() != 10)
      Thread.sleep(300L);
    for (int x = 0; x < screen.getScreenFields().getFieldCount(); x++) {
      ScreenField campo = screen.getScreenFields().getField(x);
      System.out.println(x + " : R" + campo.startRow() + "C"
          + campo.startCol() + ", len : " + campo.getFieldLength() 
          + ", value : " + campo.getString());
    }
    screen.dumpScreen();
 
and it works (of course it could be further ... polished) !

Best regards,

    Davide Grandi
PS : there's a mean to get also the protected fields ?
I'll investigate the 5250 planes.
--
Ing. Davide Grandi
[email protected]


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV