Pull HTML content from remote website and display on page

二次信任 提交于 2019-11-30 16:58:25

Extracting a fragment of HTML from a website is a breeze with simplehtmldom you can then do something like:

function pullRaspi_SDImageTable() {
    $filename = '/tmp/downloads.html';  /// Where you want to cache the result
    $expiry = 600;  // 10 minutes
    $output = '';

    if (!file_exists($filename) ||  time() - $expiry > filemtime($filename)) {
        // There is no cache, so fetch the results from remote server
        require_once('simple_html_dom.php');
        $html = file_get_html('http://www.raspberrypi.org/downloads');
        foreach($html->find('div.entry-content table.table') as $elem) {
                $output .= (string)$elem;
        }

        // Store the cache
        file_put_contents($filename, $output);
    } else {
        // Pull the content from the cahce
        $output = file_get_contents($filename);
    }

    return $output;
}

Which will give you the table.table HTML

you cannot solely use jQuery's .ajax, .load, or .get methods for this type of operation

Yes, you can BUT the remote website must give you authorization for that.. just inserting an iframe and using the normal DOM functions you could IF THERE IS NOT cross domain restrictions.

You can get a FULL page only with php (using the common functions include, require, etc and passing the website URL but, same case, you need to be authorized..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!