0

私はこのコードを持っています:

<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;
    }
}

これにより、必要な URL が取得されます。しかし、私はまた、すべての要素を取得しようとしてい<h3>ます。画像とすべてのスパンを反復しながらそれらの h3 内に取得したいのですが、あらゆる種類のことを試したので、これは頭痛の種です。誰でも光を当てることができますか?

ありがとう、

アル

4

0 に答える 0