Home Backend Development PHP Tutorial 实时抓取YAHOO股票报价的代码_PHP

实时抓取YAHOO股票报价的代码_PHP

Jun 01, 2016 pm 12:29 PM
buffer echo if code real time stock

Yahoo


function getYahooQuote($stockSymbol = "CCR")
{
if (!$targetURL) $targetURL = "http://finance.yahoo.com/q?s=$stockSymbol&d=t"; //设定要抓取的URL目标
$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, " {
$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, "
"))
{
$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 {
echo "$symbols[$i]
";
getYahooQuote("$symbols[$i]");
}
?>


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the blue screen code 0x0000001 occurs What to do if the blue screen code 0x0000001 occurs Feb 23, 2024 am 08:09 AM

What to do if the blue screen code 0x0000001 occurs

How to solve win7 driver code 28 How to solve win7 driver code 28 Dec 30, 2023 pm 11:55 PM

How to solve win7 driver code 28

How to write if in c language to judge multiple conditions How to write if in c language to judge multiple conditions Mar 25, 2024 pm 03:24 PM

How to write if in c language to judge multiple conditions

The computer frequently blue screens and the code is different every time The computer frequently blue screens and the code is different every time Jan 06, 2024 pm 10:53 PM

The computer frequently blue screens and the code is different every time

The combination of Java and WebSocket: how to achieve real-time video streaming The combination of Java and WebSocket: how to achieve real-time video streaming Dec 17, 2023 pm 05:50 PM

The combination of Java and WebSocket: how to achieve real-time video streaming

Resolve code 0xc000007b error Resolve code 0xc000007b error Feb 18, 2024 pm 07:34 PM

Resolve code 0xc000007b error

GE universal remote codes program on any device GE universal remote codes program on any device Mar 02, 2024 pm 01:58 PM

GE universal remote codes program on any device

What does the blue screen code 0x000000d1 represent? What does the blue screen code 0x000000d1 represent? Feb 18, 2024 pm 01:35 PM

What does the blue screen code 0x000000d1 represent?

See all articles