To install the latest release via LuaRocks, first ensure the requirements listed above are installed, then use the command:
luarocks install gumbo
Note: The 0.4 release only supports Unix-like systems. However,
the current git
master branch has support for Windows (via CMake),
which will be available in the next release.
gumbo module provides a
parse function and a
function, which both return a
Document node containing a tree of
descendant nodes. The structure and API of this tree mostly follows
the DOM Level 4 Core specification.
For full API documentation, see: https://craigbarnes.gitlab.io/lua-gumbo/.
The following is a simple demonstration of how to find an element by ID and print the contents of it's first child text node.
local gumbo = require "gumbo" local document = gumbo.parse('<div id="foo">Hello World</div>') local foo = document:getElementById("foo") local text = foo.childNodes.data print(text) --> Hello World
Note: this example omits error handling for the sake of simplicity.
Production code should wrap each step with
assert() or some other,
application-specific error handling.