【问题标题】:Getting html source changes dynamically from ifram tag从 iframe 标记动态获取 html 源代码更改
【发布时间】:2017-11-07 09:22:16
【问题描述】:

一段时间以来,我一直在尝试从 iframe 标记获取 html 源代码,但遗憾的是我仍然失败了。我的环境在 chrome 浏览器下,并带有 dom-distiller 扩展,它为我提供了从网页中提取主要文章的功能。此扩展适用于以下代码。

<iframe id="dom-distiller-result-iframe" 
src="chrome-extension://oiembdaoobijmdmeobkalaehgifealpl/external/chromium/src/components/dom_distiller/core/html/dom_distiller_viewer.html" 
style="z-index: 2147483647; position: fixed; 
left: 0px; right: 0px; top: 0px; bottom: 0px; 
margin: auto; width: 100vw; height: 100vh; background: white; border: none;">
</iframe>

它在我看到的网页中注入了一些 iframe 标签。使用这个 iframe 标签,可以在没有 AD 的情况下完美呈现精炼文档。我想我是否可以访问 id 为“dom-distiller-result-iframe”的 iframe 标签并获得渲染的 html 源代码。但是,我尝试了很多方法,但没有一个不起作用。

谁能给我一些建议?

【问题讨论】:

    标签: javascript jquery html extraction


    【解决方案1】:

    没有测试它,但应该做的工作:

    <?
    $url = "yoursite.com";
    
    $html = file_get_html($url);
    libxml_use_internal_errors(true); 
    
    $dom = new DOMDocument();
    $dom->loadHTML($html);
    $iFrame = $dom->getElementsByTagName('iframe')->item(0);
    $iFrameID = $iFrame->getAttribute('id');
    
    $iframehtml = file_get_html($iFrameID);
    
    echo $iframehtml;
    
    ?>
    

    【讨论】:

    • Javascript 是我的唯一选择。不管怎么说,还是要谢谢你。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    • 2013-04-06
    相关资源
    最近更新 更多