Get CSS class from other sites using PHP HTML DOM Parser

0

I'm trying to get a class from a news site, but I'm not getting it.

$titulo = $html->find('feed-post-body-title gui-color-primary gui-color-hover', 0)
               ->innertext;

echo $titulo;

You're giving this error:

  

Notice: Trying to get property of non-object

How do I get classes or ids?

    
asked by anonymous 19.09.2016 / 20:28

1 answer

0

You need to specify the element you are looking for, if it is a div , a p and etc ...

If it were a div for example, it would look like this:

// Using the "." (dot) to specify that it is a class

$titulo = $html->find('div.feed-post-body-title', 0);

or

$titulo = $html->find('div[class=feed-post-body-title]', 0);

// If you were looking for an element with id in place of the class:

// Using "#" to specify that it is an id

$titulo = $html->find('div#feed-post-body-title', 0);

or

$titulo = $html->find('div[id=feed-post-body-title]', 0);
    
31.07.2018 / 05:20