.. _splash-lua-api-overview: Splash Lua API Overview ----------------------- Splash provides a lot of methods, functions and properties; all of them are documented in :ref:`scripting-reference`, :ref:`scripting-libs`, :ref:`splash-element`, :ref:`splash-request`, :ref:`splash-response` and :ref:`binary-data`. Here is a short description of the most used ones: Script as an HTTP API endpoint ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Each Splash Lua script can be seen as an HTTP API endpoint, with input arguments and structured result value. For example, you can emulate :ref:`render.png` endpoint using Lua script, including all its HTTP arguments. * :ref:`splash-args` is the way to get data to the script; * :ref:`splash-set-result-status-code` allows to change HTTP status code of the result; * :ref:`splash-set-result-content-type` allows to change Content-Type returned to the client; * :ref:`splash-set-result-header` allows to add custom HTTP headers to the result; * :ref:`binary-data` section describes how to work with non-text data in Splash, e.g. how to return it to the client; * :ref:`lib-treat` library allows to customize the way data is serialized to JSON when returning the result. Navigation ~~~~~~~~~~ * :ref:`splash-go` - load an URL to the browser; * :ref:`splash-set-content` - load specified content (usually HTML) to the browser; * :ref:`splash-lock-navigation` and :ref:`splash-unlock-navigation` - lock/unlock navigation; * :ref:`splash-set-user-agent` allows to change User-Agent header used for requests; * :ref:`splash-set-custom-headers` allows to set default HTTP headers Splash use. * :ref:`splash-on-request` allows to filter out or replace requests to related resources; it also allows to set HTTP or SOCKS5 proxy servers per-request; * :ref:`splash-on-response-headers` allows to filter out requests based on their headers (e.g. based on Content-Type); * :ref:`splash-init-cookies`, :ref:`splash-add-cookie`, :ref:`splash-get-cookies`, :ref:`splash-clear-cookies` and :ref:`splash-delete-cookies` allow to manage cookies. Delays ~~~~~~ * :ref:`splash-wait` allows to wait for a specified amount of time; * :ref:`splash-call-later` schedules a task in future; * :ref:`splash-wait-for-resume` allows to wait until a certain JS event happens; * :ref:`splash-with-timeout` allows to limit time spent in a code block. Extracting information from a page ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * :ref:`splash-html` returns page HTML content, after it is rendered by a browser; * :ref:`splash-url` returns current URL loaded in the browser; * :ref:`splash-evaljs` and :ref:`splash-jsfunc` allow to extract data from a page using JavaScript; * :ref:`splash-select` and :ref:`splash-select-all` allow to run CSS selectors in a page; they return Element objects which has many methods useful for scraping and further processing (see :ref:`splash-element`) * :ref:`splash-element-text` returns text content of a DOM element; * :ref:`splash-element-bounds` returns bounding box of an element; * :ref:`splash-element-styles` returns computed styles of an element; * :ref:`splash-element-form-values` return values of a ``