voku / simple_html_dom

📜 Modern Simple HTML DOM Parser for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to obtain the div content of bid red in the screenshot

kl521516 opened this issue · comments

How to obtain the div content of bid red in the screenshot

image

I can't get it in the following ways:
$html_meal->findOne('#tab_show_1 table')->nextSibling()->innertext

Can you please add a minimal examples, so that I can create a test from that? Or you can also create a failing test by yourself. Thanks.

$txt = <<<___
<div class="detail J_tab" id="tab_show_1">
    <h3 class="new-tit">
        <span class="name">product detail</span>
    </h3>
    <div class="detail-tit"></div>
    <table width="100%" cellpadding="0" cellspacing="0" class="detail-table">
        <tbody>
            <tr>
                <td>aaaaa</td>
                <td class="tc">bbbb</td>
                <td class="tc">ccccc</td>
            </tr>
        </tbody>
    </table>
    <div>
        <p>
            <b>[aaaaa]</b>
        </p>
        <p></p>
        <div>bbbbbb</div>
        <div>ccccccccccccccc</div>
        <div>
            <br>
        </div>
        <p></p>
        <p>
            <b>[ddddd]</b>
        </p>
    </div>
</div>
___;
	$html_meal = HtmlDomParser::str_get_html($txt);
	$html_meal->findOne('#tab_show_1 table')->nextSibling()->innertext;

It's a whitespace issue, if you call "nextSibling()" twice you will get your expected html. :/ I can implement a loop and skip this whitespace, but I don't know if someone need to know if the next sibling-element is whitespace?

Thank you. I have one more question, how to get 2188 of this content.

<span class="main">
    <span class="old">
        Price&nbsp;
        <em>$</em>
        2188
    </span>
</span>

You can't because there is no html selector for non html selections:

  1. you can add a html tag around the price e.g. <span class="old-price">2188</span>
  2. or you can use e.g. regex 1987c34#diff-f9e35e3ee28495a595a36e0f7a4ae154R1354

PS: in version 4.7.8 there is a new method "nextNonWhitespaceSibling()" that will ignore whitespace stuff for you :)

Happy coding!

Okay, thank you for your reply again.