This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

HTML page to Lua table
#1
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?
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#2
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.
Reply


Forum Jump: