Hi there I am looking for a simple PHP only method (i.e. no JS/Jquery/Ajax on the end user) method of doing a file_get_contents or cURL after the JS has run on the source page.
I have 2 working examples, getting the specific SPAN with Class="CurrentBG" from the remote, however the content of this SPAN is created by a JS file which runs right at the end of the page. As such using both cURL and get_file_contents is leaving me with the ---
as the content and printing that, rather than the varying content (this is the default content of this SPAN until it's replaced by the JS function).
Here is my get_file_contents example
<?php
$page = file_get_contents('https://haspdenbloodglucose.herokuapp.com/');
$doc = new DOMDocument();
$doc->loadHTML($page);
$spans = $doc->getElementsByTagName('span');
foreach($spans as $span) {
// Loop through the DIVs looking for one withan id of "content"
// Then echo out its contents (pardon the pun)
if ($span->getAttribute('class') === 'currentBG') {
echo $span->nodeValue;
}
}
?>
Here is my cURL example
<?php
$curl = curl_init('https://haspdenbloodglucose.herokuapp.com/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($curl);
if(curl_errno($curl)) // check for execution errors
{
echo 'Scraper error: ' . curl_error($curl);
exit;
}
curl_close($curl);
$regex = '/<span class="currentBG">(.*?)<\/div>/s';
if ( preg_match($regex, $page, $list) )
echo $list[0];
else
print "Not found";
?>
I want to run this from a browser on a browser on Amazon Kindle Paperwhite / touch (don't ask me why haha). however sites are very limited in functionality so I an trying to keep what runs on the end users kindle as limited as possible...
This will be used to show the users blood glucose data on their tablets in a simple digital clock face style display.
Thanks