3

Simple HTML Dom を使用してリモート Web ページからキーワードをスクレイピングしていますが、これを実現する方法がよくわかりません。

現在、次のコードを使用しています。

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

そして、次のエラーを受け取ります:

Trying to get property of non-object

http://simplehtmldom.sourceforge.net/

4

4 に答える 4

11

find() はオブジェクトではなく、(この場合) 1 つのオブジェクトを含む配列を返します。また、「キーワード」は属性ではありませんが、「名前」は属性です。使用する:

$oHTML = str_get_html( $remote_html );
$arElements = $oHTML->find( "meta[name=keywords]" );
echo $arElements[0]->content;
于 2012-11-13T13:56:16.193 に答える
3
$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'); 
于 2012-11-05T02:04:25.827 に答える
2

これを試してみてください:

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

編集:

これはあなたの状況ではうまくいくかもしれませんhttp://php.net/manual/en/function.get-meta-tags.php

于 2012-07-24T21:14:17.357 に答える
2

これを試して

$Inner_anchor = file_get_html("Your-Url");
$Inner_anchor->find("head meta[name='description']", 0)->content;
于 2016-06-15T08:02:12.713 に答える