最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

實(shí)時(shí)抓取YAHOO股票報(bào)價(jià)的代碼

來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 19:02:17
文檔

實(shí)時(shí)抓取YAHOO股票報(bào)價(jià)的代碼

實(shí)時(shí)抓取YAHOO股票報(bào)價(jià)的代碼:< function getYahooQuote($stockSymbol = "CCR") { if (!$targetURL) $targetURL = "http://finance.yahoo.com/qs=$stockSymbol&d=t"; //設(shè)定要抓取的URL目標(biāo) $fd = fopen("$targetURL", "r"); $stopExtract = 0; $
推薦度:
導(dǎo)讀實(shí)時(shí)抓取YAHOO股票報(bào)價(jià)的代碼:< function getYahooQuote($stockSymbol = "CCR") { if (!$targetURL) $targetURL = "http://finance.yahoo.com/qs=$stockSymbol&d=t"; //設(shè)定要抓取的URL目標(biāo) $fd = fopen("$targetURL", "r"); $stopExtract = 0; $

<?
function getYahooQuote($stockSymbol = "CCR")
{
if (!$targetURL) $targetURL = "http://finance.yahoo.com/q?s=$stockSymbol&d=t"; //設(shè)定要抓取的URL目標(biāo)     
        $fd = fopen("$targetURL", "r");
        $stopExtract = 0;  
        $startExtract = 0;  
        while (!feof($fd))  
        {
            $buffer = fgets($fd, 4096);
                //echo trim($buffer)."\n";  
            if (strstr($buffer, "rowspan=3"))
            {
                //echo "extract started at line #$lineCount\n";  
                $startExtract = 1;  
            }     
            if ($startExtract && !$stopExtract)     
            {

                if (strstr($buffer, "<a"))  
                {
                    $startPos = strrpos($buffer, "<");
                    $buffer = substr($buffer, $startPos);
                }
                //$text = trim(strip_tags($buffer));
                //echo trim($buffer)."\n";  

                $buffer = str_replace("\n\r", " ", "$buffer");
                if (strstr($buffer, "http://ichart.yahoo.com/v?s=$stockSymbol"))  
                {
                    //echo "ichart found!";
                    $stopExtract = 1;  
                }
                $capturedHTML .= $buffer;     

            }
            if ($startExtract && strstr($buffer, "<br>"))
            {
                 $stopExtract = 1;  
                //echo "extract stopped at line #$lineCount\n";          
                echo $capturedHTML;
                break;
            }
            $lineCount++;
        }
        fclose($fd);
    }

    //以下為抓取的一個(gè)例子
    $symbols = array('CCR', 'IIXL','SAPE','WBVN' );
    $symbolCount = count($symbols);
    for ($i=0; $i< $symbolCount; $i++)
    {
        echo "$symbols[$i]<br>";
        getYahooQuote("$symbols[$i]");
    }
    ?>


聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

實(shí)時(shí)抓取YAHOO股票報(bào)價(jià)的代碼

實(shí)時(shí)抓取YAHOO股票報(bào)價(jià)的代碼:< function getYahooQuote($stockSymbol = "CCR") { if (!$targetURL) $targetURL = "http://finance.yahoo.com/qs=$stockSymbol&d=t"; //設(shè)定要抓取的URL目標(biāo) $fd = fopen("$targetURL", "r"); $stopExtract = 0; $
推薦度:
標(biāo)簽: 腳本 Yahoo 股票代碼
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top