2017-05-01 105 views
0

我需要在我的網頁上加載,修改和輸出一些第三方iframe。如所建議的那樣,我創建了簡單包含及其src屬性的中間頁面。DOMxpath查詢不返回

PHP代碼輸出的頁面看起來是這樣的:

$iframe->loadHTML(file_get_contents("http://example.com/iframe_page.php")); //creating DOM object, see htm content below 
$xpathObj= new DOMXPath($iframe);//creating DOMXPath object 
foreach ($xpathObj->query('//div[@id="specific_id"]') as $node){ //this query returns nothing 
    $node->parentNode->removeChild($node);//i need to remove the div with that id, but there is nothing to remove 
} 
echo $iframe->saveHTML($iframe->documentElement);//the iframe output works fine 

而且我iframe的內容看起來是這樣的:

<html> 
    <head> 
    </head> 
    <body> 
     <div> 
      <div> 
       <div id="specific_id"> 
       </div> 
      </div> 
     </div> 
    </body> 
</html> 

我甚至嘗試禁用JS,看看這個div放在那裏通過前端代碼和禁用JS禁用文件的結構看起來完全一樣。

+0

你確定你有這個'html'內容嗎?因爲你的代碼工作正常以上.. –

+0

你的代碼工作檢查此https://eval.in/785036 –

+0

@SahilGulati我確定它,它的結構無論如何...還有什麼其他的東西可以在這裏玩? – RWS

回答

0

答案很簡單。您不能使用PHP DOMDocument操作iframe元素crossdomain。