0

I have a table of data, I want to capture the text inside of the element that immediately follows a element that has a label inside with a title attribute of "label". See the table here:

<table>
<tr>
    <th><label title="Country">Country</label></th>
    <td>I want to capture this text</td>
</tr>
<tr>
    <th><label title="Other">Heading I don't need</label></th>
    <td>Cell I don't Need</td>
</tr>
</table>

The only identifiable characteristic I can find is that the td is preceded by a th that has a label inside that has a unique title attribute.

First, I tried it without the label since I know it's going to be the first result for:

$found = $html->find('tr th')->next_sibling();
echo($found[0]);

But that doesn't appear to be the correct usage of next sibling. Can somebody tell me how to correctly use it to get the element that follows a element? Even better if there is someway to incorporate that label with its unique title attribute.

hhwhy
  • 23
  • 2
  • 4
  • possible duplicate of [Get text from next tag](http://stackoverflow.com/questions/4920695/get-text-from-next-tag) – Gordon Nov 22 '11 at 23:34

1 Answers1

0

Can somebody tell me how to correctly use it to get the element that follows a element?

Next sibling does not return its content. Instead u should use first_child().

Even better if there is someway to incorporate that label with its unique title attribute.

What do you mean 'to incorporate' ? You can use find() to get contents of every label nevertheless it has title or not. If you want to get content of a label with specified title then you should mention your title in find(). I suggest you to read the manual: http://simplehtmldom.sourceforge.net/manual.htm

animalnots
  • 29
  • 4
  • 1
    Care to comment you code, how does it works, how does it solves OP question? – Yaroslav Oct 09 '12 at 06:52
  • I see you already updated your answer. It has nothing to do with the question made by the OP, it is closely related to the SO philosophy and how to write good answers. Check [here](http://meta.stackexchange.com/questions/7656/how-do-i-write-a-good-answer-to-a-question) and [here](http://meta.stackexchange.com/questions/118582/what-is-an-acceptable-answer) for more details. And last but not least, the Jon Skeet blog about [how to answer a technical question](http://msmvps.com/blogs/jon_skeet/archive/2009/02/17/answering-technical-questions-helpfully.aspx) – Yaroslav Oct 09 '12 at 07:24
  • This answer shows a fundamental misunderstanding of the OP's question. next_sibling() or nextSibling() is supposed to be able to get the next element in line such as:

    TITLE

    Second Title

    If you use ->find('h2'), and then ->next_sibling() You should come to the

    but Simple HTML DOM only returns an error.

    – j_allen_morris Feb 01 '19 at 04:46