我在过去的 5 个小时里一直在寻找解决方案,我不敢相信我在这里问我的第一个问题是因为一个简单的问题,所以代码是:
$urlContents = file_get_contents('http://www.google.com');
$dom = new DOMDocument();
$contents = $dom->loadHTMLFile($urlContents); //$contents = 'source code from www-google.com'
$divsInDomDoc = $dom->getElementsByTagName('div'); // $divsInDomDoc becames a DomNodeList with length = 0
$nNodes = $divsInDomDoc->length // using this to check length
请有人帮忙!