首頁 >後端開發 >php教程 >即時抓取YAHOO股票報價的代碼_PHP教程

即時抓取YAHOO股票報價的代碼_PHP教程

WBOY
WBOY原創
2016-07-21 16:03:351261瀏覽


function getYahooQuote($stockSymbol = "CCR")
{
if (!$targetURL) $targetURL = "http://finance.yahoo.com/q?s=$stockSymbol&d=t "; //設定要提取的URL目標     
        $fd = fopen("$targetURL", "r");
    = 0;  
        while ( !feof($fd))  
        {
            $ //迴聲修剪($buffer)."n";  
            if (strstr($buffer , "rowspan=3"))
            {
                      $startExtract = 1;  
            }     $stopExtract)     
            {

                if (strstr($buffer, "                {
                    $startPos = strrpos($buffer, "                    $ buffer = substr($buffer, $startPos);
                }
                     //迴聲修剪($buffer)."n";  

                $buffer = str_replace("nr", " ", "$buffer");
   s=$stockSymbol" ))  
               {
             ";
                    $stopExtract = 1;  
                }
                $capturedHTML .= $buffer;     

            }
            if ($startExtract && strstr($buffer, "
") )
            {
                 $stopExtract = 1;  
                //echo "提取在#$lineCountn行停止";          
                echo $capturedHTML;
                休息;
            }
            $lineCount ;
        }
        fclose($fd);
    }

    //以下為抓取的例子
    $symbols = array('CCR', 'IIXL','SAPE','WBVN' );
  );
    for ($i=0; $i    {
        ymbols[ $i]");
    }
    ?>



http://www.bkjia.com/PHPjc/316198.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316198.htmlTechArticle? function getYahooQuote($stockSymbol = CCR) { if (!$targetURL) $targetURL = http://financeSymbolance .yahoo.com/q?s=$stockSymbolquot;; //設定要抓取的URL目標$fd = fopen($targetURL, r)...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn