2017-05-01 56 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。