DOMxpath查询什么都不返回 [英] DOMxpath query returns nothing

查看:96
本文介绍了DOMxpath查询什么都不返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的网页上加载,修改并输出一些第三方 iframe 。正如所建议的那样,我创建了一个中间页面,它只包含< iframe> 及其 src 属性。

I need to load, modify and output some 3rd party iframe on my webpage. As suggested, I had created the intermediary page that simply contains <iframe> with its src attribute.

输出页面的php代码如下所示:

The php code that outputs the page looks like this:

$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的nope文档的结构看起来完全一样。

I've even tried disabling JS to see if this div is placed there by front-end code and nope with JS disabled the structure of the document looks exactly the same.

推荐答案

答案很简单。您无法使用PHP DOMDocument操纵iframe元素交叉域。

The answer is rather simple. You CAN'T manipulate iframe element crossdomain using PHP DOMDocument.

这篇关于DOMxpath查询什么都不返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆