There is a text:

<p>my text</p> <a>link text</a> <div>my text</div> 

I got the text between p

 $a = $html->find('p',0); echo $a->plaintext; 

How to get text from a div? number of a, p and div set. There are no definitions for a div by class and nothing else, you just need to get the following div tag.

  • the next tag a will be - Naumov
  • @Neatek Lay out the source of the page on PASTEBIN. There is no point in guessing it (if there is really a lot of such good). I advise you only to see if the required <div> is in some already defined node and can be identified. Identified - get the right div - Vlad
  • @Naumov The author is not likely to fit the количество a, p и div множество - Vlad
  • @Maksym You probably did not read correctly, he chooses <p> because searching for find('p',0) breaks out and thinks that this is a I just corrected it for the idea should help $html->find('a',0)->next() although it is not clear what he wants - Naumov
  • @Naumov I agree. Not clear) - Vlad

1 answer 1

Use the DOM navigation. Navigation begins with the body , or any other element.

DOM elements have the properties firstElementChild (the first child) and lastElementChild (the last child). After you have decided which root tag you have, and received its first element, you can move along its child tags forward ( nextElementSibling ) and backward ( previousElementSibling ).

Here is an example for clarity. There are many div 's in it and they all look the same (no id or class ), but only one contains the word we need (win):

 var root=document.getElementById("root"); var winNode=root.firstElementChild.firstElementChild.nextElementSibling.firstElementChild.nextElementSibling; alert(winNode.textContent); 
 <div id="root"> <div> <div>fail</div> <div> <div>fail</div> <div>win</div> </div> </div> </div> 

  • By tags it is clear that the question is not about javascript - Neatek