Reading data from updated JavaScript html

Is it possible to read the updated quotes in real time this site via actionscript3 without reloading the page all the time, which is heavy on the net.

In other words, is it possible to pass quotes directly to actionscript3 or eventually PHP from javascript?

If anyone has any suggestion on how to get these quotes in actionscript?

+2


source to share


2 answers


Extending what Theo Said ... (I'm sure there is a much easier way to do this and I'll be frowned upon as a hack, but it works damnit)

I basically just extract the first two numbers under EUR / USD in red.

Here's a php script to host on your server called getContent.php

<?php

$handle = fopen("getVars.php", "r");

$contents = '';
    while (!feof($handle)) {
     $contents .= fread($handle, 8192);
}

$vars = explode("&",  $contents);
$time = substr($vars[2], 5);
$difference = abs(date(s)-$time);

if($difference>5)
{

    $handle = fopen("http://www.fxstreet.com/technical/currencies-glance/pair.aspx?id=EUR/USD", "r");

    $contents = '';
        while (!feof($handle)) {
         $contents .= fread($handle, 8192);
    }

    $contents=trim($contents);
    $pos1 = strpos($contents, 'lhtml_0" innerOnUpdate="att=BID" innerfilter="format_number">');
    $str1 = substr($contents, $pos1, 100);
    $cur1 =  substr($str1, 61, 6); 
    $pos2 = strpos($contents, 'lhtml_1" innerOnUpdate="att=ASK" innerfilter="format_number">');
    $str2 = substr($contents, $pos2, 100);
    $cur2 = substr($str2, 61, 6); 

    $cachedPage = fopen("getVars.php", "w");
    $varString = "cur1=$cur1&cur2=$cur2&time=".date(s);
    fwrite($cachedPage,$varString);
    fclose($cachedPage);
    echo "cur1=$cur1&cur2=$cur2&cached=false";
}
else
{
    $handle = fopen("getVars.php", "r");

    $contents = '';
        while (!feof($handle)) {
         $contents .= fread($handle, 8192);
    }

    echo $contents."&cached=true";
}

fclose($handle);
?>

      

And then ActionScript



var updateTimer:Timer = new Timer(5000);
updateTimer.addEventListener(TimerEvent.TIMER, getQuotes);
updateTimer.start();
function getQuotes(e:Event):void
{
    var request:URLRequest = new URLRequest ("getContent.php");     
    var loader:URLLoader = new URLLoader (request);
    loader.addEventListener(Event.COMPLETE, onComplete);
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.load(request);
}

function onComplete (event:Event):void
{
   var variables:URLVariables = new URLVariables( event.target.data );
   currency1.text = variables.cur1;
   currency2.text = variables.cur2;
}
var e:Event;
getQuotes(e);

      

You can see it in action here ... http://www.hupcapstudios.com/getCurrency.swf

Part of the hack is my parsing the page in php. I had to do some serious tuning action. I'm sure someone with a decent amount of parsing capabilities could write cleaner code to extract all the data you need.

I just thought that I would rock it. Good luck :)

+2


source


it is possible to create a server-side script that checks the site content every 5 seconds or so. The script can parse the "cached" version of the "quote" you want to retrieve. Then just request that cached content via URLRequests at short intervals from your flash app.



+1


source







All Articles