Functions
Code Block | ||
---|---|---|
| ||
[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
...
output after printing the variable "table"
first | second |
---|---|
a | b |
c | d |
function a
...
:
Create an html link element with title that will open in new tab
Code Block | ||
---|---|---|
| ||
var link=httphtml.a("https://google.com","Google",true); print(link); |
...
output after printing the variable "link"
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.
Code Block | ||
---|---|---|
| ||
var cnnAsHtml=http.get("http://www.cnn.com/");
var headerElement=html.find("a.link-banner h2.screaming-banner-text", cnnAsHtml);
print(headerElement.toString()); |