php dom 找不到任何节点

php dom not able to find any nodes

我正在尝试使用此代码获取所有锚点 (a) 标签的 href

$obj = json_decode($client->getResponse()->getContent());
$dom = new DOMDocument;
if($dom->loadHTML(htmlentities($obj->data->partial))) {

  foreach ($dom->getElementsByTagName('a') as $node) {
      echo $dom->saveHtml($node), PHP_EOL;
      echo $node->getAttribute('href');
  }
}

其中返回的 JSON 类似于 here 但它不回显任何内容。 HTML 确实有一个标签,但永远不会运行 foreach。我做错了什么?

只需删除 htmlentities()。它会工作得很好。

$contents = file_get_contents('http://jsonblob.com/api/jsonBlob/54a7ff55e4b0c95108d9dfec');
$obj = json_decode($contents);
$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML($obj->data->partial);
libxml_clear_errors();
foreach ($dom->getElementsByTagName('a') as $node) {
    echo $dom->saveHTML($node) . '<br/>';
    echo $node->getAttribute('href') . '<br/>';
}