skip to Main Content

I would like to know if it is possible to save only a part of a web page as HTML after it is finished rendering.

Let’s say I have a web page, on this web page there is a tile view. This tile view is a UL list with an ID.

After this finishes loading, I would like to save away only this UL list as an HTML file, so that the next time I load the page, under defined circumstances, I load/output this HTML file and don’t have to do the "tiling" functions.

I have already found this, how to generally save a page as HTML
https://stackoverflow.com/a/3775302/11813184
But unfortunately nothing about whether I can also save away only a certain area, such as a UL list with a defined ID.

2

Answers


  1. Try to use SimpleHTMLDom library for your needs – https://simplehtmldom.sourceforge.io/manual.htm

    This is like jQuery, but for PHP.

    $html = file_get_html('http://www.google.com/');
    
    // Find all anchors, returns a array of element objects
    $ret = $html->find('ul');
    
    // Find (N)th anchor, returns element object or null if not found (zero based)
    $ret = $html->find('a', 0);
    
    // Find lastest anchor, returns element object or null if not found (zero based)
    $ret = $html->find('a', -1);
    
    // Find all <div> with the id attribute
    $ret = $html->find('div[id]');
    
    // Find all <div> which attribute id=foo
    $ret = $html->find('div[id=foo]');
    
    Login or Signup to reply.
  2. I have used successfully ob_start and ob_get_contents as they are described here. Save current page as HTML to server

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search