使用 Simple HTML Dom 检索关键字元标记内容? [英] Retrieve keywords meta tag content with Simple HTML Dom?

查看:33
本文介绍了使用 Simple HTML Dom 检索关键字元标记内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Simple HTML Dom 从远程网页上抓取关键字,但我不知道如何实现这一点.

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;

并收到以下错误:

Trying to get property of non-object

http://simplehtmldom.sourceforge.net/

推荐答案

find() 返回的不是一个对象,而是一个包含(在本例中)1 个对象的数组.此外,'keywords' 不是属性,但 'name' 是.使用:

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;

这篇关于使用 Simple HTML Dom 检索关键字元标记内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆