문제

실시간 업데이트 된 따옴표를 읽을 수 있습니까? 이 웹 사이트 ActionScript3을 통해, 항상 페이지를 다시로드 할 필요없이 네트워크가 많은 것입니다.

다시 말해서, Quote-Data를 ActionScript3 또는 JavaScript의 PHP로 직접 스트리밍 할 수 있습니까?

이 인용문을 ActionScript에 가져 오는 방법에 대한 제안이 없다면 누구입니까?

도움이 되었습니까?

해결책

Theo가 말한 내용을 확장 ...

나는 본질적으로 EUR/USD에서 처음 두 숫자를 빨간색으로 추출하고 있습니다.

다음은 GetContent.php라는 서버에 넣을 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);
?>

그리고 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);

여기서 실제로 볼 수 있습니다 ... http://www.hupcapstudios.com/getcurrency.swf

해킹 부분은 PHP에서 페이지를 구문 분석하는 것입니다. 나는 심각한 서브 스트링 행동을해야했다. 적절한 양의 구문 분석 능력을 가진 사람은 필요한 모든 데이터를 추출하기 위해 클리너 코드를 작성할 수 있다고 확신합니다.

방금 스윙을 할 것이라고 생각했습니다. 행운을 빕니다 :)

다른 팁

5 초마다 사이트의 내용을 확인하는 서버 측 스크립트를 만들 수 있습니다. 스크립트는 검색하려는 "인용"의 "캐시 된"버전을 구문 분석 할 수 있습니다. 그런 다음 플래시 애플리케이션에서 짧은 간격으로 UrlRequest를 통해이 캐시 된 컨텐츠를 요청하십시오.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top