我想从一个网站获取特定的div元素(即属性id="vung_doc"
),但我几乎获得了每个元素。你有什么想法吗?如何从网站获取特定的div?
$doc = new DOMDocument;
// We don't want to bother with white spaces
$doc->preserveWhiteSpace = true;
// Most HTML Developers are chimps and produce invalid markup...
$doc->strictErrorChecking = false;
$doc->recover = true;
$doc->loadHTMLFile('http://lightnovelgate.com/chapter/epoch_of_twilight/chapter_300');
$xpath = new DOMXPath($doc);
$query = "//*[@class='vung_doc']";
$entries = $xpath->query($query);
var_dump($entries->item(0)->textContent);
非常感谢您! – sh33pS0ldat