DOMXPath var_dump:“(省略对象值)”

时间:2013-07-01 04:10:47

标签: php html xpath data-extraction

$store = curl_exec($ch); // Returns a page of HTML

$doc = new DOMDocument();
$doc->loadHTML($store);
$xpath = new DOMXpath($doc);

Vardump $xpath

object(DOMXPath)#2 (1) { 
    ["document"] => string(22) "(object value omitted)" 
} 

这里有什么问题?我正在尝试在HTML代码上使用xpath来提取信息。

object(DOMDocument)#1 (34) {
    ["doctype"]         => string(22) "(object value omitted)" 
    ["implementation"]  => string(22) "(object value omitted)" 
    ["documentElement"] => string(22) "(object value omitted)" 
    ["actualEncoding"]  => string(6) "gb2312" 
    ["encoding"]        => string(6) "gb2312"
    ["xmlEncoding"]     => string(6) "gb2312" 
    ["standalone"]      => bool(true) 
    ...

1 个答案:

答案 0 :(得分:3)

loadHTMLFile要求html文件的路径不是html文件loadhtmlfile的内容。所以你的代码将是

$doc = new DOMDocument();
$doc->loadHTMLFile("path to html file");
$xpath = new DOMXpath($doc);

修改

如果您想从html内容加载,请使用loadhtml

$doc = new DOMDocument();
$doc->loadHTML($store);
$xpath = new DOMXpath($doc);