且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从远程页面获取iframe内容?

更新时间:2023-02-23 20:11:04

您将无法使用javascript访问iframe内的远程页面文档原始政策。

You won't be able to access the document of a remote page inside an iframe using javascript because of the same origin policy.

如果你知道页面的URL,你可以使用PHP CURL来检索它

If you know the URL of the page you can use PHP CURL to retrieve it

<?php 
        // Initialise a cURL object
        $ch = curl_init(); 

        // Set url and other options
        curl_setopt($ch, CURLOPT_URL, "http://page-with-some-iframe.com");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

        // Get the page contents
        $output = curl_exec($ch); 

        // close curl resource to free up system resources 
        curl_close($ch);