View Only
Expand all | Collapse all

Using GEL to read content from a static HTML web page

Jump to Best Answer
  • 1.  Using GEL to read content from a static HTML web page

    Posted Oct 11, 2016 02:27 PM

    Hi guys!  We're trying to read content out of an HTML static web page.  Very simple and straightforward... but it looks like there's no way to do so using GEL.  Already tried gel:parse, file:readFile and ftp:get with no luck so far.


    Any ideas?




  • 2.  Re: Using GEL to read content from a static HTML web page
    Best Answer

    Posted Oct 11, 2016 04:16 PM

    There are many way to accomplish this:


    Here is a way to pull everything from the web page into a string.


    <?xml version="1.0" encoding="utf-8"?>

         <!-- StringBuilder for the output -->
         <core:new className="java.lang.StringBuilder" var="stringBuilder" />

         <!-- URL for the web url -->
         <core:new className="" var="url">
              <core:arg type="java.lang.String" value=""/>

         <!-- Open and read the response stream -->
         <core:set var="httpUrl" value="${url.openConnection()}" />
         <gel:out>Encoding Type</gel:out>
         <core:new className="" var="inputStreamReader">
              <core:arg type="" value="${httpUrl.getInputStream()}"/>
         <core:new className="" var="bufferedReader">
              <core:arg type="" value="${inputStreamReader}"/>

         <!-- l anoop through the response appending each line into the stringbuilder -->
         <core:set var="line" value="" />
         <core:while test="${line != null}">
              <core:set var="line" value="${bufferedReader.readLine()}" />
              <core:if test="${line != null}">
                   <core:invoke method="append" on="${stringBuilder}">
                        <core:arg value="${line}" />

         <!-- Close the bufferReader -->
         <core:if test="${bufferedReader != null}">
              <core:invoke method="close" on="${bufferedReader}" />

         <core:new className="" var="FileOne">
              <!-- /fs0/clarity1/share/UrlOutput.txt -->
              <core:arg type="java.lang.String" value="UrlOutput.txt"/>

         <core:invoke method="println" on="${FileOne}">
              <core:arg value="${stringBuilder.toString()}" />

    <!--     <gel:out>${stringBuilder.toString()}"</gel:out>-->
         <gel:out>End this Script</gel:out>


     It also save the string to a file.


    If you are looking for specific stings, you could load the web page into a java.util.Scanner and regex out the values you are looking for.