selectAll

selectAll ( string cssSelector , string _code , string _selection ) : string[]

Select all elements in code using a css selector, by default on all the source code but you can indicate a portion of code, the selection correspond to what you want it return.

In this function the actions are executed in this order:
1) _code is parsed
2) cssSelector is searched in the parsed DOM
3) Once the DOM element is located, we search the property defined in _selection



Example

HTML:

<ul id="listofLanguages"> 
<li>Java </li> 
<li>Python </li> 
<li>Groovy </li>
<li><em> C++</em>  </li> 
</ul>

Grimport:

language = selectAll("#listofLanguages") 
console(language) // -> ["Java", "Python", "Groovy", "<em> C++</em>"]


Tip

When you iterate through the rows of a table, if you put the contents of the tr into a variable and then reinject it into a select, the code parser won't work because only a td or tr without a table is invalid. You need to recreate a valid table structure to create valid, parsable HTML code.
featuresHTML = """<table border="1">
<tr>
<th>Product</th>
<th>Specifications</th>
</tr>
<tr>
<td>Laptop A</td>
<td>8GB RAM, 256GB SSD</td>
</tr>
<tr>
<td>Smartphone B</td>
<td>6.5" Display, 128GB Storage</td>
</tr>
</table>"""

for(tr in selectAll("tr", featuresHTML))
{
tr = "<table><tr>" + tr + "</tr></table>" // -> <table><tr> <th>Product</th> <th>Specifications</th> </tr></table>
labelFeature = get(cleanSelectAll("td", tr), 0)
valueFeature = get(cleanSelectAll("td", tr), 1)
}


See also

select
cleanSelect
cleanSelectAll

Parameters

cssSelector

Use Inspect element in your browser to find the CSS selector. CSS Selector reference.
It is working for XML also.

_code (optional)

The HTML or XML code where the cssSelector should be searched. If null it is the page code in a FORPAGE script.

_selection (optional)

What do you want to extract the element from the HTML DOM?
• innerHTML or html (by default) = HTML inner the element
• outerHTML = HTML outer the element
• text = text in the element
• object = return the Elements Jsoup object
• other value = the name of the attribute in the tag
Note attribute can be "abs:href" for absolute links in a href attribute