抓取YAHOO股票報價的類
更新時間:2009年05月15日 23:50:17 作者:
實時抓取YAHOO股票報價的函數(shù),大家可以學(xué)習(xí)一下思路跟具體的代碼,自己可以拓寬下。
復(fù)制代碼 代碼如下:
<?
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);
}
//以下為抓取的一個例子
$symbols = array('CCR', 'IIXL','SAPE','WBVN' );
$symbolCount = count($symbols);
for ($i=0; $i< $symbolCount; $i )
{
echo "$symbols[$i]<br>";
getYahooQuote("$symbols[$i]");
}
?>
相關(guān)文章
PHP+MySQL高并發(fā)加鎖事務(wù)處理問題解決方法
這篇文章主要介紹了PHP+MySQL高并發(fā)加鎖事務(wù)處理問題解決方法,結(jié)合實例形式分析了PHP+MySQL事務(wù)處理相關(guān)操作技巧與注意事項,需要的朋友可以參考下2018-04-04PHP中的print_r 與 var_dump 輸出數(shù)組
下面小編就為大家?guī)硪黄狿HP中的print_r 與 var_dump 輸出數(shù)組。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考2016-06-06php中base64_decode與base64_encode加密解密函數(shù)實例
這篇文章主要介紹了php中base64_decode與base64_encode加密解密函數(shù),實例分析了base64加密解密函數(shù)的具體用法,具有一定的實用價值,需要的朋友可以參考下2014-11-11PHP中uploaded_files函數(shù)使用方法詳解
PHP uploaded_files函數(shù)的功能非常強大,希望通過這篇文章中介紹的內(nèi)容能夠幫助我們解決相關(guān)問題,提高我們對PHP語言的了解程度。2011-03-03