Logic Machine Forum
HTML page to Lua table - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: HTML page to Lua table (/showthread.php?tid=646)



HTML page to Lua table - Thomas - 25.02.2017

Hi
Can I convert a webpage (returned as a string from http.request) to a Lua table? M isea is to convert DOM in the same way as json library parse json to table.
Now I parse the webpage using string manipulation functions like match, gsub etc. I don't trust this code so much so I would like to improve my code by a more robust solution. Is there any suitable library in LM?

Thank you

And subquestion: I need to convert the webpage into something LM understands. Which codepage Lua or LM uses internally? Is it UTF8? Is there iconv available in LM?


RE: HTML page to Lua table - admin - 27.02.2017

LuaExpat library for parsing XML is built-in but it probably won't work because most web pages are invalid XML documents.
There are some pure Lua parsers like https://github.com/thenumbernine/htmlparser-lua, but you will have to adapt the code a little bit for it to run in LM.

Web interface uses UTF-8. All Lua string functions work only on byte level so they mostly don't care about encoding. iconv is not provided by default but can be provided as a separate package later.