How to obtain the div content of bid red in the screenshot
kl521516 opened this issue · 6 comments
kl521516 commented
voku commented
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.
kl521516 commented
$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;
voku commented
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?
kl521516 commented
Thank you. I have one more question, how to get 2188 of this content.
<span class="main">
<span class="old">
Price
<em>$</em>
2188
</span>
</span>
voku commented
You can't because there is no html selector for non html selections:
- you can add a html tag around the price e.g.
<span class="old-price">2188</span>
- 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!
kl521516 commented
Okay, thank you for your reply again.