码迷,mamicode.com
首页 > Web开发 > 详细

php抓取股票数据

时间:2017-04-01 01:17:16      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:actor   xls   抓取   epo   hpc   ram   com   https   ice   

 public function stock(){
        $curl = new Curl();
        $curl->setUserAgent(‘Mozilla/5.0‘);
        $curl->get(‘http://stock.gtimg.cn/data/get_hs_xls.php?id=ranka&type=1&metric=chr‘);
        $file_name = date(‘Ymd‘).‘.xls‘;
        if ($curl->error) {
            echo $curl->error_code;
        }
        else {            
            file_put_contents($file_name, $curl->response);
            //echo $curl->response;
            $objPHPExcel = \PHPExcel_IOFactory::load($file_name);
            $sheet = $objPHPExcel->getSheet(0);
            $highestRow = $sheet->getHighestRow(); // 取得总行数
            $highestColumn = $sheet->getHighestColumn(); // 取得总列数
            $objdata = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
            dump($objdata);
        }
        
        $curl->close();
        
    }

composer

{   
    "require": {
        "php": ">=5.4.0",
        "topthink/framework": "^5.0",
	"phpoffice/phpexcel": "^1.0",
	"curl/curl": "^1.0"
    },
    "repositories": {
        "packagist": {
            "type": "composer",
            "url": "https://packagist.phpcomposer.com"
        }
    }
}

  

php抓取股票数据

标签:actor   xls   抓取   epo   hpc   ram   com   https   ice   

原文地址:http://www.cnblogs.com/nowphp/p/6654054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!