N
N
ndtvdx2014-12-01 18:25:37
Parsing
ndtvdx, 2014-12-01 18:25:37

How to get content using simple_html_dom?

Please tell me how to get the text using simple_html_dom:
"A room for rent in a 2-room apartment, a room with a good repair, there is all the necessary furniture and household appliances. A girl lives in the second room. I am considering: 2 girls, or a married couple. RF , CIS. 89151124838",
with the following code:

<tr class="second selected" id="realty-id-5426521" realtyId="5426521">
    <td valign="top" class="" colspan="5">
        <div class="more-top" style="position:relative; top:0px;">
            <div class="expand-title pull-left">			
                <a target="_blank" href="/arenda/Moskva/t17_komnaty/mitinskaya-48-sdaetsya-komnata-kom-kv-komnata-horoshim-remontom-est-vsya-neobhodimaya-mebel-bytovaya_5426521" class="title">
                    <span class="fio">Владелец</span> сдаст комнату:
                </a>
            </div>     
        </div>     
Сдается комната в 2-х ком. кв, комната с хорошим ремонтом, есть вся необходимая мебель и бытовая техника. Во второй комнате проживает девушка. Рассматриваю: 2 девушки, либо семейная пара. РФ, СНГ. 89151124838	
        <div class="more-main"></div>
        <div class="more-bottom">
            <div class="btn-abuse btn btn-small btn-danger pull-right" data-html="true" data-placement="bottom" rel="popover-abuse">
            Оставить отзыв <small>▼</small>
            </div>
            <div class="js-editMy btn btn-small btn-info pull-right m-right10"> Редактировать <i class="icon-edit icon-white"></i>
            </div> 
            <div class="clearfix"></div>
        </div>
        <div class="more-info">
            Объект добавлен 30 ноября 23:37 
        </div>
    </td>
    <td colspan="1" valign="top" align='right'></td>						
</tr>

The problem is that this text is not enclosed in a separate tag, because of this it is impossible to get its contents.
I'm trying to do this:
foreach ($html->find('tr[class=selected]') as $element) {
$result['text'][] = trim($element->text());
}

It doesn't work.. I can't pull it out from parent elements either.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg ak-o, 2014-12-01
@ndtvdx

try this:
foreach($html->find('tr.selected') as $element) {
echo $element->text();
}
But for some reason I did not find a method that will return the contents of the text without descendants.
So most likely you will have to cut them all out first, leaving the desired text ... Good luck)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question