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

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

瓦杜普$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) 
    ...
4

1 回答 1

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);
于 2013-07-01T04:17:02.383 回答