set_time_limit(0);
$max_time=3600;
$cache_file='cache_yahoo.txt';
$nowtime=time();
if(!file_exists($cache_file)){
$filetime=0;
}else{
$filetime=filemtime($cache_file);
}
if($filetime+$max_time<$nowtime){
//更新
ob_start();
function get_yahoo_info($url){
$content=file_get_contents($url);
$pattern='|
(.*) \((.*)\) (.*)|U'; preg_match_all($pattern,$content,$out); $info['company_name']=$out[1][0]; $info['company_stock']=$out[2][0]; $pattern='| 最近交易价: (.*) |U'; preg_match_all($pattern,$content,$out); $info['stock_price']=$out[1][0]; $pattern='|涨跌: (.*) |U'; preg_match_all($pattern,$content,$out); $info['stock_upordown']=$out[1][0]; $pattern='|市值: (.*) |U'; preg_match_all($pattern,$content,$out); $info['stock_value']=$out[1][0]; return $info; } $urls=explode(',',file_get_contents('url.txt')); $i=0; $matchs=array(); foreach($urls as $url){ $rs=get_yahoo_info($url); if(!empty($rs)){ $matchs[$i]=$rs; $i++; $rs=''; } } //print_r(get_yahoo_info('http://cn.finance.yahoo.com/q?s=000063.SZ')); ?> 公司名称
股票代号
股票价格
股票涨幅
市值
$i=1; foreach($matchs as $match){ ?> =$i?> =$match['company_name']?>
=$match['company_stock']?>
=$match['stock_price']?>
=$match['stock_upordown']?>
=$match['stock_value']?>
$i++; }?>
$content=ob_get_clean(); $fp=fopen($cache_file,'w'); if(!$fp)echo '打开文件失败'; if (flock($fp, LOCK_EX)) { // 进行排它型锁定 if(!fwrite($fp, $content))echo '文件写入失败'; flock($fp, LOCK_UN); // 释放锁定 } else { //echo "Couldn't lock the file !"; if(!fwrite($fp, $content))echo '文件写入失败'; } fclose($fp); //echo 'cache time:'.time(); echo $content; }else{ //echo 'cache!'; echo file_get_contents($cache_file); } ?>
http://www.bkjia.com/PHPjc/317727.html www.bkjia.com true http://www.bkjia.com/PHPjc/317727.html TechArticle 以前在公司就写过类似的东西,这次是帮以前的上司写了一个简单的采集程序。 很简单的。。汗。没什么技术含量的。 数据来源:http://c...
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
Latest Articles by Author
2024-10-22 09:46:29
2024-10-13 13:53:41
2024-10-12 12:15:51
2024-10-11 22:47:31
2024-10-11 19:36:51
2024-10-11 15:50:41
2024-10-11 15:07:41
2024-10-11 14:21:21
2024-10-11 12:59:11
2024-10-11 12:17:31