Simple HTML Dom を使用してリモート Web ページからキーワードをスクレイピングしていますが、これを実現する方法がよくわかりません。
現在、次のコードを使用しています。
$html = str_get_html($remote_html);
echo $html->find("meta[keywords]")->content;
そして、次のエラーを受け取ります:
Trying to get property of non-object
Simple HTML Dom を使用してリモート Web ページからキーワードをスクレイピングしていますが、これを実現する方法がよくわかりません。
現在、次のコードを使用しています。
$html = str_get_html($remote_html);
echo $html->find("meta[keywords]")->content;
そして、次のエラーを受け取ります:
Trying to get property of non-object
find() はオブジェクトではなく、(この場合) 1 つのオブジェクトを含む配列を返します。また、「キーワード」は属性ではありませんが、「名前」は属性です。使用する:
$oHTML = str_get_html( $remote_html );
$arElements = $oHTML->find( "meta[name=keywords]" );
echo $arElements[0]->content;
$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');
これを試してみてください:
$html->find('meta[description]');
編集:
これはあなたの状況ではうまくいくかもしれませんhttp://php.net/manual/en/function.get-meta-tags.php
これを試して
$Inner_anchor = file_get_html("Your-Url");
$Inner_anchor->find("head meta[name='description']", 0)->content;