Search code examples
javajavascriptdomgeckogeckofx

Add listener to DOM element HTML update. Gecko, C#.Net, Java


I'm looking at the following site: www.example.com

I'm navigating to the site with a GeckoWebBrowser object and taking a snapshot of the HTML of the object every second. Then I navigate the DOM to get the table I want (div = 'tableContainer'), get the InnerHTML of this element, and parse the table to a C#.Net Dataset. I can then create 'Price' objects and carry on processing the updates.

I would like to do this asynchronously: without the need to check the HTML of the element in a loop. If there's no update, I don't want to do anything. If there is an update, I want to collect the HTML (preferably just for a row/column/cell that has updated!!). How can I do either of the folllowin

this.geckoWebBrowser1.Window.Scripter.AddEventListener("updateItem_inJavaScriptCode", new EventHandler<DOMJSONStringEventArgs>(OnMyExtensionEvent));

or

Skybound.Gecko.GeckoElement tableContainer = gwb.Document.GetElementById("tableContainer");
tableContainer+= new GeckoDOMElementHTMLCHANGEDUPDATE(methodToCallWithDOMUpdate);`

I'd appreciate any suggestions for this in Java or C#.Net or any pointers at all.

Thanks.


Solution

  • See: https://developer.mozilla.org/en/DOM/DOM_event_reference

    To my knowledge none of the events you require are part of the standard but if you're only developing for a client you control there is no problem I suppose.

    This is of course the wrong to go about it. Why don't you skip the HTML scraping step and fetch the data directly from whatever webservice the webpage plugs into?

    I see the DOM as only a UI model, it's not a source of data. The source of data should be your webservices.