3
我使用PHP的DomDocument并试图刮出来的东西,看起来像这样:获取有itemprop的属性的所有元素
<div itemprop='movie'>Fight Club</div>
它也可能是这样的:
<span itemprop='musician'>Ozzy Osbourne</span>
我想抓取页面上的所有itemprop='n'
,并将它们放入数组中以存储它们的nodevalue以及相关的itemprop名称。到目前为止我的代码看起来是这样的:
function getItemprops(){
foreach($this->dom->getAttribute("itemprop") as $buffer) {
$itempropList = array(
'theNodeValue' => $buffer->nodeValue,
'theItemprop' => $buffer->getAttribute("itemprop")
)
return $itempropList;
}
}
我的代码应该沿线的某处得到一个数组:
array (
array(
0 =>
"theNodeValue" => "Fight Club",
"theItemprop" => "movie"
1 =>
"theNodeValue" => "Fight Club",
"theItemprop" => "movie"
)
)
不幸的是,我的代码返回Fatal error: Call to undefined method DOMDocument::getAttribute()
。
所以基本上,我想选择所有itemprop=""
的并将它们放入数组中。
感谢您的帮助!
非常感谢! –