PDA

View Full Version : lua DOM Parser?



kwaugh
November 21st, 2009, 06:47 AM
I use the HA7NET ethernet bridge to poll my 1-wire devices. it's responses are returned as HTML that I've been parsing with substring finds based on the returned format. For example below is a piece of a returned response with a temperature

<INPUT CLASS="HA7Value" NAME="Temperature_0" ID="Temperature_0" TYPE="text" VALUE="17.6562">

Are there a set of lua libraries (and could you give an example!) of how I could parse the VALUE information from this more efficiently?

I'm guessing that when done properly, I could iterate through the names "Temperature_0", "Temperature_1" and pull the values vs my current string searches.

Thanks!

K

Rob H
November 21st, 2009, 10:57 AM
I would recommend using the htmltidy library which should be included with Girder - not much in the way of documentation or examples at present though I'm afraid. The advantage of this is that it can cope with badly-formed HTML

Take a look at http://www.bessems.biz/luatidy/ and check the readme.txt in the source code archive, and also the link to htmltidy itself.

It's been a while since I used it. I did write an htmltidyutils.lua file which may or may not be included with Girder - let me know if it isn't and I'll upload it here.

kwaugh
November 21st, 2009, 01:43 PM
Thanks Rob - that got me going in the right direction.

I'm now putting the results (which are very ill formed) through tidy to make them usable, then through a parser via lxp to extract what I need.

Two steps vs the 1 I was hoping for, but still much, much better then my string search based approach!

Thanks again!

K

Rob H
November 21st, 2009, 03:35 PM
You shouldn't need lxp - you can traverse the DOM in the htmltidy object.