Clarity

 View Only
  • 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?

     

    Thanks!

    Patricio



  • 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"?>
    <gel:script
         xmlns:core="jelly:core"
         xmlns:log="jelly:log"
         xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


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

         <!-- URL for the web url -->
         <core:new className="java.net.URL" var="url">
              <core:arg type="java.lang.String" value="http://www.ca.com/us/default.aspx"/>
         </core:new>

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

         <!-- 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}" />
                   </core:invoke>
              </core:if>
         </core:while>

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

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

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

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

    </gel:script>

     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.

     

    V/r,

    Gene