[英]How can I get html from a specific node using DOMDocument()
我正在使用$ doc = new DOMDocument();
我只想從特定ID而不是整個HTML中獲取HTML。
我試過了
$file=file_get_contents($url);
$doc = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$doc->load($file);
$content = $doc->getElementById("site-content");
echo $doc->saveHTML($content);
但這不起作用。
<?php
$file=file_get_contents("https://www.wikipedia.org/");
$doc = new DOMDocument();
$doc->loadHtml($file);
$content = $doc->getElementById("searchInput");
echo $doc->saveHTML($content);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.