私は巨大なStringとして私に来るHTMLを解析しようとしています。私が13行目に行くと、NodeChild page = it.parent()
Html Sloping in Groovy
私が探しているキーを見つけることができますが、データはThis Is Value One In My KeyThis is Value Two in my KeyThis is Value Three In My Key
のように私に届きます。私は、2つの間のセパレータが常にUppercaseUppercase(WithoutSpaces)であるという定期的な傾向を見ています。
私はそれをArrayList
に入れたいと思います。私が逃している方法がありますか?from the docsこれは自動的にこれを行うことができますか?これを一緒に解析するより良い方法はありますか?
class htmlParsingStuff{
private def slurper = new XmlSlurper(new Parser())
private void slurpItUp(String rawHTMLString){
ArrayList urlList = []
def htmlParser = slurper.parseText(rawHTMLString)
htmlParser.depthFirst().findAll() {
//Loop through all of the HTML Tags to get to the key that I am looking for
//EDIT: I see that I am able to iterate through the parent object, I just need a way to figure out how to get into that object
boolean trigger = it.text() == 'someKey'
if (trigger){
//I found the key that I am looking for
NodeChild page = it.parent()
page = page.replace('someKey', '')
LazyMap row = ["page": page, "type": "Some Type"]
urlList.add(row)
}
}
}
}
私は何かに上だと思う大丈夫、実現しませんでした'.parent'、' .children'、 '.childNodes'を呼び出すことができます –