Groovy XmlSlurper
- by Langali
I am trying to parse a html file using Groovy XmlSlurper.
<div id="users">
<h1>Name: Joe Doe</h1>
<div id="user">
<div id="user_summary">Game: 1</div>
<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/DApLO_HDhD0&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/DApLO_HDhD0&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
</div>
<div id="user">
<div id="user_summary">Game: 2</div>
...
</div>
<div id="user">
....
</div>
</div>
<div id="featured_users">
<div id="user">
...
</div>
<div id="user">
....
</div>
</div>
I need to grab each user (and not featured user) with his name, summary and object tag (which the video embed code).
Anybody wanna give it a shot?
Here's a start:
def parser =new XmlSlurper(new org.ccil.cowan.tagsoup.Parser())
def response = parser.parseText(htmlString)
def users = response.depthFirst().collect { it }.findAll { it.@id == "users" }
users.each {
......
}
I cant seem to be able to get much further: