在phpquery中获取节点值

时间:2013-03-13 13:03:16

标签: php html dom phpquery

我试图在抓取我的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

1 个答案:

答案 0 :(得分:3)

试试这个它会起作用.......

$doc = phpQuery::newDocumentFileHTML('myurl');
$new_data = array();
foreach($doc['#filter-reload.row h1'] as $value)
{
    $new_data[] = $value->nodeValue;
}