1

在抓取我的 html 页面后,我试图从 phpquery 获取节点值。

$doc = phpQuery::newDocumentFileHTML('myurl');

foreach($doc['#filter-reload.row h1'] as $value)
{
print_r($value);
exit;
}

我得到的输出为

DOMElement Object ( [tagName] => h1 [schemaTypeInfo] => [nodeName] => h1 
[nodeValue] => Oz The Great And Powerful (PG) [nodeType] => 1 [parentNode] => (object value omitted) 
[childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => (object value omitted)

我只想要 nodeValue 作为输出......但是如何得到它?

我试过:-

$doc['#filter-reload.row h1']->nodeValue //not working
$doc['#filter-reload.row h1']['nodeValue']//notworking
4

1 回答 1

3

试试这个它会工作.......

$doc = phpQuery::newDocumentFileHTML('myurl');
$new_data = array();
foreach($doc['#filter-reload.row h1'] as $value)
{
    $new_data[] = $value->nodeValue;
}
于 2013-03-13T13:23:56.713 回答