Jump to content

how can I extract this data


desjardins2010

Recommended Posts

Guys I'm trying to get a certain piece of info in the quickest possible way so the site don't load slow when fetching..

 

the site i'm getting data from is silverclix.com and the piece I wan't is the Total Paid and total Members at the top of the screen

 

the pieces of info are in this list

<!-- #statistics -->
        <div class="span8" id="statistics">
                	<section>
              <ul>
                <li class="total-paid">Total Paid: <span>$22,204.32</span></li>
                <li class="total-members">Total Members: <span>31912</span></li>
                <li class="users-online">Users Online: <span></span></li>                                      
              </ul>
            </section>
            
        </div>
        <!-- #statistics ends -->

and I have tried this...

<?php
			$content = file_get_contents('http://www.silverclix.com/index.php');

			preg_match('#<ul><li>(.*)total-paid</li></ul>#', $content, $match);
			$total_paid = $match[1];		
		
		?>

that hasn't worked so if anyone can help please   

Link to comment
https://forums.phpfreaks.com/topic/284749-how-can-i-extract-this-data/
Share on other sites

Don't use regular expressions to parse or navigate through HTML. Use DOMDocument to load it and then DOMXPath to get to that specific part of the HTML using the (untested) example query

//div[@id='statistics']/section/ul/li[@class='total-paid']/span

The documentation for DOMXPath::query has a relevant example - HTML versus XML doesn't really make a difference in what you do (beside changing a couple method calls). If you want to see the book.xml it uses, it's here.

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.