Retrieve keywords meta tag content with Simple HTML Dom?

10,526

Solution 1

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;

Solution 2

$headers = array();
$headers["title"] = $html-> find("title",0)-> plaintext;
$headers["keywords"] = $html-> find("meta[name=keywords]",0) ->getAttribute('content');  
$headers["description"] = $html-> find("meta[name=description]",0) ->getAttribute('content'); 

Solution 3

Give this a shot:

$html->find('meta[description]');

EDIT:

This might work better for your situation http://php.net/manual/en/function.get-meta-tags.php

Solution 4

Try this

$Inner_anchor = file_get_html("Your-Url");
$Inner_anchor->find("head meta[name='description']", 0)->content;
Share:
10,526
Muggles
Author by

Muggles

Updated on June 05, 2022

Comments

  • Muggles
    Muggles almost 2 years

    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/