html

Functions

[string] p([string] p); // return an html paragraph element(<p>)
[string] br(); // return an html new line
[string] element([string] tag); // return empty tag
[string] element([string] tag, [string] innerHtml); //return and element with inner Html
[string] a([string] linkUrl); // return an <a>
[string] a([string] linkUrl, [string] title); // return an <a> with title
[string] a([string] linkUrl, [string] title, [boolean] target); // if target==true will open in new window
[string] table([StringArray] headers[],[String2dArray] rows[][]) // return a table
[org.jsoup.select.Elements] find([string] selector, [string] html) // return an element object based on the css selector

Examples

function table:

Create an html table and store it into variable table

var table=html.table(["first","second"],
						[["a","b"],["c","d"]]);
print(table);

variable "table" contains:

"<table><thead><tr><th>first</th><th>second</th></tr></thead><tbody><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>d</td></tr></tbody></table>"

output after printing the variable "table"

firstsecond
ab
cd

function a:

Create an html link element with title that will open in new tab

var link=html.a("https://google.com","Google",true); 
print(link);

variable "link" contains:

<a href="https://google.com" title="Google">Google</a>

output after printing the variable "link"

Google

function find:

Will find elements that will be selected by the passed css selector, please check org.jsoup.select.Elements  api.

We're trying to print the head line news in CNN website, it's not an efficient way since CNN may change it's website structure or some of the content mat load by scripts after site loaded.

var cnnAsHtml=http.get("http://www.cnn.com/");
var headerElement=html.find("a.link-banner h2.screaming-banner-text", cnnAsHtml);
print(headerElement.toString());