Alaska Software Inc. - First usage of XbpHtmlViewer/XbpHtmlWindow
Username: Password:
AuthorTopic: First usage of XbpHtmlViewer/XbpHtmlWindow
Pascal BoivinFirst usage of XbpHtmlViewer/XbpHtmlWindow
on Wed, 01 Feb 2017 20:11:14 +0100
Hi

A customer ask me to save a value from a web page. The web page is from
a device in a factory.  But for everyone to understand I will call this
device a "Printer", and the value is the ink level. By opening a web
page with the IP adress of the printer, I see a web page with a menu on
the left. By clicking an item it load a new page (let's say
InkLevel.htm) in the center frame and show the ink level.

<td class="val" id="ink_level">0</td>

There is a Java script on the page to update this value every 0.5
seconds. If I open directly InkLevel.htm the Javascript is not
executed. I guess the call is on the main menu page.

I remember in another language I was doing something like
oWebViewer:Document:ChildNode(2):ChildNode(1)... and finally reach the
value.

Can I use XbpHtmlViewer to load the page, then transfer this to
XbpHtmlWindow to get the value? I don't see how to use XbpHtmlWindow on
a web page.
Andreas Gehrs-Pahl
Re: First usage of XbpHtmlViewer/XbpHtmlWindow
on Thu, 02 Feb 2017 01:42:26 -0500
Pascal,

>By clicking an item it load a new page (let's say InkLevel.htm) in the 
>center frame and show the ink level.
><td class="val" id="ink_level">0</td>

It seems to me that you are mostly interested in the Ink Level value, and 
not so much in displaying the page, even though you could do both.

If you have the Professional Subscription, the easiest way to access the 
Ink Level data is with LoadFromURL() and HRF (the Alaska HTML Reflection 
Framework). The following code will print the Ink Level value every 5 
seconds until you press the ESC key:

#include "ASINet.ch"
#include "Inkey.ch"
#pragma Library("HRFClass.lib")

Procedure Main()
   while .t.
      ? Get_Ink_Level()
      if Inkey(5) == K_ESC
         exit
      endif
   enddo
return

Function Get_Ink_Level()
LOCAL cURL   := 'http://YourHost/YourPath/InkLevel.htm'
LOCAL cHTML  := LoadFromURL(cURL)
LOCAL cFile  := Save_File(cHTML)
LOCAL oPage  := HTMLDocument():LoadFile(cFile)
LOCAL cLevel := ''
LOCAL oLevel
   if ValType(oPage) == 'O'
      oLevel := oPage:GetElementById('ink_level')
      if ValType(oLevel) == 'O'
         cLevel := oLevel:GetContent()
      endif
   endif
   FErase(cFile)
return (cLevel)

Function Save_File(cText)
LOCAL cFileName := GetUniqueFileName(, 'htm')
   if .not. empty(cText)
      MemoWrit(cFileName, cText)
   endif
return (cFileName)

>There is a Java script on the page to update this value every 0.5
>seconds. If I open directly InkLevel.htm the Javascript is not
>executed. I guess the call is on the main menu page.

As you can see, you can simply reload the same page in your program at any 
interval that makes sense to you. But the current XbpHtmlWindow() class 
can't execute Java (or any other) Scripts. To execute JavaScript, you would 
need to use the XbpHTMLViewer() class, which is basically a wrapper for the 
MS (Microsoft) IE (InternetExplorer) ActiveX component. This class will not 
give you access to the internal rendering or processing, though.

If and when Alaska replaces the current HTML Renderer (HTMLayout) with a 
new one (Chromium), you will probably have access to all the internals of 
the web page, including the JaveScript data. But when that will happen is 
anyone's guess.

Hope that helps,

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[F]:   https://www.facebook.com/AbsoluteSoftwareLLC
Pascal BoivinRe: First usage of XbpHtmlViewer/XbpHtmlWindow
on Thu, 02 Feb 2017 20:44:56 +0100
Hi Andreas

The LoadFromUrl trick would work if the web page not required execution
of Javascript, but that is not the case.

You gave me an hint when you talk about Chromium. I'll look at 
https://en.wikipedia.org/wiki/Chromium_Embedded_Framework

to see if I can use that.

Thank you
Thomas BraunRe: First usage of XbpHtmlViewer/XbpHtmlWindow
on Tue, 07 Feb 2017 13:59:58 +0100
Pascal Boivin wrote:

> The LoadFromUrl trick would work if the web page not required execution
> of Javascript, but that is not the case.
> 
> You gave me an hint when you talk about Chromium. I'll look at 
> https://en.wikipedia.org/wiki/Chromium_Embedded_Framework
> 
> to see if I can use that.

I find it quite strange to parse a website to get such information.

Is there a chance to use SNMP instead to query the device?

I'm using http://www.net-snmp.org/ to gather data from my routers and a
temperature measuring device about in/outgoing traffic and server
temperatures.

Thomas
Pascal BoivinRe: First usage of XbpHtmlViewer/XbpHtmlWindow
on Tue, 07 Feb 2017 14:09:29 +0100
In all other case we use appropriate driver to talk directly to the
device. But this one is a "home made" with no documentation.
Thomas BraunRe: First usage of XbpHtmlViewer/XbpHtmlWindow
on Wed, 08 Feb 2017 08:18:43 +0100
Pascal Boivin wrote:

> In all other case we use appropriate driver to talk directly to the
> device. But this one is a "home made" with no documentation.

Andreas Gehrs-Pahl
Re: First usage of XbpHtmlViewer/XbpHtmlWindow
on Wed, 08 Feb 2017 10:10:51 -0500
Pascal,

>In all other case we use appropriate driver to talk directly to the
>device. But this one is a "home made" with no documentation.

In my experience, a lot of the things that are done with JavaScript on web 
pages are unnecessary and can be done just as easily manually, such as the 
retrieval of images, etc. You may want to look at the code and see what it 
does to retrieve the Ink Level from the device and then try do the same 
directly, with LoadFromURL() or low level socket functions, in case it 
utilizes AJAX or the Web Socket protocol.

It's probably worth a try.

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[F]:   https://www.facebook.com/AbsoluteSoftwareLLC