xpathで次の情報を取得するにはどうすればよいですか?
テキスト 01 - link_1.com
テキスト 02 - link_2.com
$page = '
<div class="news">
<div class="content">
<div>
<span class="title">Text 01</span>
<span class="link">link_1.com</span>
</div>
</div>
<div class="content">
<div>
<span class="title">Text 02</span>
<span class="link">link_2.com</span>
</div>
</div>
</div>';
@$this->dom->loadHTML($page);
$xpath = new DOMXPath($this->dom);
// perform step #1
$childElements = $xpath->query("//*[@class='content']");
$lista = '';
foreach ($childElements as $child) {
// perform step #2
$textChildren = $xpath->query("//*[@class='title']", $child);
foreach ($textChildren as $n) {
echo $n->nodeValue.'<br>';
}
$linkChildren = $xpath->query("//*[@class='link']", $child);
foreach ($linkChildren as $n) {
echo $n->nodeValue.'<br>';
}
}
私の結果は戻ってきています
テキスト 01
テキスト 02
link_1.com
link_2.com
テキスト 01
テキスト 02
link_1.com
link_2.com