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);
    ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.