在Groovy Xmlparser / Xmlslurper中迭代html文件

时间:2017-04-12 11:15:14

标签: groovy xmlslurper

我有来自包含50个地址的网站的商店价值,

  <div class="storeContainer">
      <div class="storeCount">50</div>
      <div class="mapAddress" id="store50">
         <h4 onclick="changeMap(50,38.872432,-78.530463);">Woodstock, VA</h4>
         <h5>Woodstock Square</h5>467 West Reservoir Road
<br/>540-459-7505
<br/>
         <a href="https://maps.google.com/maps?saddr=geo&amp;daddr=467+West+Reservoir+Road+Woodstock+VA+22664&amp;sll=38.872432,-78.530463&amp;sspn=0.011265,0.014098&amp;z=12"
            class="getDirections">Get Directions</a>
      </div>
   </div>
</div>

这是一个商店示例,我得到的格式相同。我希望逐个迭代

  

Woodstock,VA

     伍德斯托克广场

     

西水库路

     

540-459-7505

https://maps.google.com/maps?saddr=geo&daddr=467+West+Reservoir+Road+Woodstock+VA+22664&sll=38.872432,-78.530463&sspn=0.011265,0.014098&z=12

我尝试使用以下代码

def envelope = new XmlParser().parseText(xml);

envelope.'**'.find { it.@class == 'mapAddress' }.with { node ->
    println h4.text()
    println h5.text()
    println a.@'href'
    println node.children().findAll { it.getClass() == String }*.trim()
}

到目前为止没有运气。

0 个答案:

没有答案