私は次のようないくつかのDOMをページスクレイプしようとしています:
<span>text</span>
そして時々このように見えます:
<span><p>text</p></span>
text
しかし、私は2番目のシナリオに入る方法を理解できないようです。私はいくつかの方法を試しました、そしてこれが私が以下でうまくいくと思ったものです:
def html = slurper.parse(reader)
Collection<NodeChild> nodes = html.'**'.findAll { it.name() == 'span' && it.@class == 'style2' }
...
def descriptionNode = html.'**'.find { it.name() == 'span' && it.@class == 'style20' }
def innerNode = descriptionNode.'**'.find { it.name() == 'p' }
def description
if (innerNode?.size() > 0)
{
description = innerNode.text()
}
else
{
description = descriptionNode.text()
}
必要な動作を取得するためにxmlslurperを使用する必要がある方法はありますか?