Search code examples
phpregexweb-scrapingcurldom

php extract only selected rows from external table


I want to extract only a select number of rows from a table that exists on an external site. I am using the response in the following post as a start to extract the entire table:

PHP Data Extraction From External Website, Then Write to Database

It works great for getting the whole table, but what I want to accomplish is as follows.

1) exclude the first row

2) include the next 7 rows

3) exclude the rest of the table

Can this be done?


Solution

  • For my specific purposes I used the following class http://sourceforge.net/projects/simplehtmldom/

    And the following php code to get exactly what I want from the html table I am scraping.

        <?php 
    
        include('../includes/simple_html_dom.php');
    
        $html = file_get_html('http://listhoopla.com/r.cgi/276');
    
        $ret = $html->find('tr');
    
        ?><table><?
        $x=1;
        while($x<8){
        echo $ret[$x];
        $x++;
        }
        ?>
        </table>