【发布时间】:2017-05-01 11:38:26
【问题描述】:
我需要在我的网页上加载、修改和输出一些第 3 方iframe。正如建议的那样,我创建了一个中间页面,它只包含 <iframe> 及其 src 属性。
输出页面的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 禁用文档的结构看起来完全一样。
【问题讨论】:
-
你确定你有这个
html的内容吗?因为您的代码在上面运行良好.. -
您的代码正在运行检查此eval.in/785036
-
@SahilGulati 我确定是的,它的结构无论如何......这里还有什么其他的东西可以玩?
-
你能分享你完整的
HTML内容吗,因为你上面的代码在这里工作正常eval.in/785036