lundi 20 avril 2015

Call to a member function next_sibling() on a non-object

I'm using HTML Dom Parser to get the contents of HTML page.

The page has something like this structure

<div id = 'someID'>
    content
</div>
<noscript>
  data that I want to extract
</noscript>

So I tried to to extract <noscript> tag something like that

$noScript = $html->find('<noscript>', 2)->plaintext;

it was 3rd noscript tag in HTML

but it returned nothing.

after that I tried to get the next_subling()

$noScript = $html->find('#someID', 0)->next_subling()->plaintext;

it's working just fine, but sometimes there is no next_subling to that ID, in that case it throws Fatal Error.

can anybody help me that how can I make it conditional, I mean if next_subling() exist, get it, otherwise ignore it.

I tried to wrap this into if statement but nothing came out of box..

help help help...

Aucun commentaire:

Enregistrer un commentaire