Jump to content

PHP scraping multiple tags SimpleHTMLDom


acctman

Recommended Posts

The html file i'm scraping from has 11 boxevent div classes and I want to loop through them and grab the results and team name for each. Am I doing it the right way? Also how can I loop through all float-right result and team classes grabbing the data.

 

 

    <div class="boxevent">

        <div class="row">

            <span class="float-right result">4</span>

            <span class="team" title="Pittsburgh Power ">PIT</span>

        </div>

        <div class="row">

            <span class="float-right result">12</span>

            <span class="team" title="Orlando Predators ">ORL</span>

        </div>

    </div>

   

    <div class="boxevent">

        <div class="row">

            <span class="float-right result">24</span>

            <span class="team" title="Atlanta ">ATL</span>

        </div>

        <div class="row">

            <span class="float-right result">6</span>

            <span class="team" title="Miami ">MIA</span>

        </div>

    </div>

 

 

**php**

    <?php
    include 'includes/simple_html_dom.php';
    $html = new simple_html_dom();
    $html = file_get_html('http://score...', false, $context); 
    
    $score0 = $html->find('span[class=float-right result]', 0);
    $score1 = $html->find('span[class=float-right result]', 0);
    
    $team0 = $html->find('span[class=team]', 0);
    $team1 = $html->find('span[class=team]', 0);
          
    /* out */
    
    echo '<pre>';
    
    print_r($score0);
    print_r($score1); 
    print_r($team0);
    print_r($team1);
    
    echo '</pre>';
    
    $html->clear(); 
    unset($html);
    ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.