I'd like to parse an HTML page and get the table values. For example parsing through it to get a list of dictionaries. Each list element would be a dictionary corresponding to a row in the table.
Let's say that the table is:
table
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
result
[Jill, Smith, 50]
[Eve, Jackson, 94]
I'm achieving this by two ways:
Using Xpath :
page.body.div.table.tr.time;
Using closure like this:
page."**".findAll { it.@class.toString().contains("time")}.each {
Both ways use XMLSlurper:
@Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='1.2')
def parser = new XmlSlurper(new org.ccil.cowan.tagsoup.Parser())
So is there another way of getting table values using groovy
Thanks for the help!