实时抓取YAHOO股票报价的代码_php基础

<?
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, "<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]");
    }
    ?>

时间: 2024-11-29 00:12:03

实时抓取YAHOO股票报价的代码_php基础的相关文章

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

<? function getYahooQuote($stockSymbol = "CCR") { if (!$targetURL) $targetURL = "http://finance.yahoo.com/q?s=$stockSymbol&d=t"; //设定要抓取的URL目标             $fd = fopen("$targetURL", "r");         $stopExtract

抓取YAHOO股票报价的类_php技巧

复制代码 代码如下: <? function getYahooQuote($stockSymbol = "CCR") { if (!$targetURL) $targetURL = "http://finance.yahoo.com/q?s=$stockSymbol&d=t"; //设定要抓取的URL目标 $fd = fopen("$targetURL", "r"); $stopExtract = 0; $sta

javascript实时抓取天气和汇率的代码

问题描述 javascript实时抓取天气和汇率的代码 前台直接通过接口抓取,网上的说明看不懂啊,有没有完整代码好好研究一下,谢谢了

分享下页面关键字抓取components.arrow.com站点代码_php实例

复制代码 代码如下: <?php /** * HOST: components.arrow.com */ //set_time_limit(0); // base function function curl_get($url, $data = array(), $header = array(), $timeout = 15, $port = 80, $reffer = '', $proxy = '') { $ch = curl_init(); if (!empty($data)) { $da

php抓取https的内容的代码_php技巧

直接用file_get_contents,会报错: 复制代码 代码如下: $url = (https://xxx.com"); file_get_contents($url); 错误: Warning: file_get_contents(https://xxx.com) [function.file-get-contents]: failed to open stream: No such file or directory in D:wampwwwgrabber_clientindex.ph

一个从别的网站抓取信息的例子(域名查询)_php基础

<?   if (isset($xx)) { $dodo=@file("http://www.e9china.com/cgi-bin/comdns.pl?raw=1&lookup=OK&fqdn=".$fqdn."&domain=".$domain."&root=".$root."&cdomain=2.7");    $i=0; while($dodo[$i]) {    echo

php下通过curl抓取yahoo boss 搜索结果的实现代码

1.编写curl类,进行网页内容抓取 复制代码 代码如下: class CurlUtil { private $curl; private $timeout = 10; /** * 初始化curl对象 */ public function __construct() { $this->curl = curl_init(); curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->curl, CURLO

实时抓取网页数据

问题描述 本人非编程出身,跪求大神指导最近在做一个程序,需要用到网页上实时变化的数字进行分析,求一段能实时抓取网页变化数字的程序. 解决方案 解决方案二:轮询可以实现解决方案三:具体点,给个例子解决方案四:写个循环啊......用线程控制时间解决方案五:有类似的例子吗jkdkud

asp 抓取baidu收录网页数代码

asp 抓取baidu收录网页数代码 <% response.expires = -1 response.addheader "cache-control","no-cache" Response.AddHeader "Pragma","no-cache" wd=Request("d") If Request("s")="baidus" Then BaiduUr