desjardins2010 Posted December 13, 2013 Share Posted December 13, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/284749-how-can-i-extract-this-data/ Share on other sites More sharing options...
requinix Posted December 13, 2013 Share Posted December 13, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/284749-how-can-i-extract-this-data/#findComment-1462285 Share on other sites More sharing options...
desjardins2010 Posted December 13, 2013 Author Share Posted December 13, 2013 great comment and I'm sure it's better option but I have no clue about DOMDocument so.... any chance in written me a little something and explaining how it works?? Quote Link to comment https://forums.phpfreaks.com/topic/284749-how-can-i-extract-this-data/#findComment-1462287 Share on other sites More sharing options...
requinix Posted December 13, 2013 Share Posted December 13, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284749-how-can-i-extract-this-data/#findComment-1462289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.