Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---HTML Source to Be scraped:---
- <div id="latest-stats" class="row section--wrapper three text-center">
- <div class="col-xs-12">
- <h2>Current Situation in Florida</h2>
- <p class="sml">Updated as of Mon 4/6/2020 06:02 PM ET</p>
- </div>
- <div class="situation__boxes-wrapper">
- <div class="col-xs-12 col-md-8 outer--box outer--box--left">
- <div class="inner--box">
- <h4>Positive Cases of COVID-19 in Florida</h4>
- <div class="stat--box">
- <!-- TRYING TO GET THIS plaintext value 13214--> <h2>13214</h2>
- <p>Confirmed Cases in Florida Residents</p>
- </div>
- <div class="stat--box">
- <!--THIS VALUE--> <h2>415</h2>
- <p>Cases in Non-Florida Residents</p>
- </div>
- <div class="stat--box">
- <!--AND THIS VALUE--> <h2>13629</h2>
- <p>Total Cases Overview</p>
- </div>
- </div>
- </div>
- ---PHP CODE SO FAR---
- <?php
- include('simple_html_dom.php');
- $html = file_get_html('https://floridahealthcovid19.gov/#lateststats');
- //echo $html->find('title', 0)->plaintext;
- $list = $html->find('div[class="stat--box"]');
- //First Method i'm trying to get to work
- foreach( $list->find('h2') as $element) {
- echo $element->plaintext;
- echo "<br />";
- }
- //Second method I'm saving JIC
- //$list_array = $list->find('h2');
- /*for($i = 0; $i < sizeof($list_array); $i++ ) {
- echo $list_array[$i];
- echo "<br />";
- }
- */
- ?>
- ---I'M USING SIMPLE-DOM-PARSER---
- I'm not even close to a final solution but can't even seem to loop through the child <h2> tags within the div class ="stat--box"> with an exception being thrown:
- Fatal error: Uncaught Error: Call to a member function find() on array in D:\xampp\htdocs\flcovid\web_scraper.php:19 Stack trace: #0 {main} thrown in D:\xampp\htdocs\flcovid\web_scraper.php on line 19
- Can someone point me in the right direction? I've found plenty of tutorials and walk-throughs with respect to getting the values in top-level tags but with respect to good examples digging into nested child element values I haven't had any luck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement