我有这个代码:
<code>
<div id="accordion" class="ui-accordion ui-widget ui-helper-reset" role="tablist">
<h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-state-focus" role="tab"
aria-expanded="false" tabindex="0">
<a><img class="img" alt="NOS" src="/images/small-nos.png"><span>10:00</span>NOS</a></h3>
<div class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" role="tabpanel"
style="display: none; ">
<a href="/news1276" target="_blank">Today's headlines</a>
<h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-state-focus" role="tab"
aria-expanded="false" tabindex="0">
<a><img class="img" alt="SBS" src="/images/small-sbs.png"><span>11:00</span>SBS</a></h3>
<div class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" role="tabpanel"
style="display: none; ">
<a href="/news1278" target="_blank">Nieuws</a>
</div>
</div>
</code>
我正在做的是以下内容:
// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$accordions = $xpath->query("//div[@id='accordion']/div");
// Iterate events
for($i = 0; $i < ($accordions->length); $i++) {
// The node
$event = $accordions->item($i);
// The urls of the node
$urls = $xpath->evaluate('.//a/@href', $event);
if ($urls->length > 0)
{
$result[$i] .= $urls->item(0)->value;
}
}
这让我得到了我想要的网址。然而,我也在尝试获取<h3>
's 中的所有元素,我想在迭代时检索这些 h3 中的图像和所有跨度,但这让我很头疼,因为我已经尝试了各种各样的东西。任何人都可以阐明一下吗?
谢谢,
铝