0
我試圖解析HTML,將它作爲一個巨大的字符串來給我。當我到達13號線時,NodeChild page = it.parent()
H Groovy中的Slurping
我能夠找到我正在尋找的鑰匙,但數據像我這樣來到This Is Value One In My KeyThis is Value Two in my KeyThis is Value Three In My Key
等等。我發現兩者之間的分隔符始終是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'' –