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

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

WBOY
發布: 2016-07-21 16:03:35
原創
1267 人瀏覽過


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)...
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板