您提供的样本用于
jsoup
def headers = docParser.select("tr > th").collect { it.text() }
def result = []
docParser.select("tr:has(td)").each { tr ->
def obj = [:]
tr.select("td").eachWithIndex { Element td, int i ->
obj[headers[i]] = td.text()
}
result << obj
}
println JsonOutput.prettyPrint(JsonOutput.toJson(result))
-
docParser.select("tr > th").collect { it.text() }
收集表头并将其按顺序存储
List<String>
-
docParser.select("tr:has(td)")
选择包含数据的所有行(不包括表头)
-
tr.select("td").eachWithIndex
i
-
最后一行显示到控制台的所需输出
输出:
[
{
"TransactionName": "1 /aumentum/",
"AverageLatency": "1648.0",
"MinimumLatency": "1240",
"MaximumLatency": "2900",
"AverageElapsedTime": "1907.0",
"MinimumElapsedTime": "1495",
"MaximumElapsedTime": "3140",
"TotalCount": "45",
"PassPercentage": "100.0"
},
{
"TransactionName": "T01_Aumentum_Home",
"AverageLatency": "6.0",
"MinimumLatency": "1",
"MaximumLatency": "10",
"AverageElapsedTime": "1956.0",
"MinimumElapsedTime": "1490",
"MaximumElapsedTime": "3806",
"TotalCount": "213",
"PassPercentage": "0.0"
}
]
https://gist.github.com/wololock/651a536dff4e104ebba0eef69d4ac3ea