首页 > 代码库 > php抓取股票数据

php抓取股票数据

 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抓取股票数据