Retrieve keywords meta tag content with Simple HTML Dom?

Muggles picture Muggles · Jul 24, 2012 · Viewed 10k times · Source

I am using Simple HTML Dom to scrape keywords off remote web pages but I can't figure out quite how to achieve this.

I am currently using the following code.

$html = str_get_html($remote_html);
echo $html->find("meta[keywords]")->content;

And receiving the following error:

Trying to get property of non-object

http://simplehtmldom.sourceforge.net/

Answer

Marthein picture Marthein · Nov 13, 2012

find() returns not an object but an array containing (in this case) 1 object. Also 'keywords' is not an attribute, but 'name' is. Use:

$oHTML = str_get_html( $remote_html );
$arElements = $oHTML->find( "meta[name=keywords]" );
echo $arElements[0]->content;