分类:
2009-12-30 18:07:43
//包含共用函数库
include_once('Gather_Base.php');
final class bank extends Gather_Base{
private $homepage='';
private $classname='bank';
private $encoding='shift-jis';
function __construct(){
//调用父类的构造方法,增加两个参数,
//一个是类名,一个是编码
parent::Gather_Base($this->classname,$this->encoding);
}
//得到数据
function getData(){
$games=$this->getGames($this->homepage);
if($games===false)return false;
//每个游戏处理
foreach($games as $name=>$http){
echo "\nGame:$name\n";
$this->log('Game',$name);
$price=$this->getPrice($http['sell']);
if($price!==false)
$this->areasSell[$name]=$price;
$price=$this->getPrice($http['buy']);
if($price!==false)
$this->areasBuy[$name]=$price;
}
}
function getPrice($http){
if(!$http)return false;
$thisGame=array();
$doc=$this->get($http);
$doc=$this->getMiddle($doc,'cart_t');
$table=$this->getTableData($doc);
//dump($table);exit;
$headers=$table[1];
$favorCount=count($headers);
$last='last area';
for($i=2;$i<count($table);$i+=2){
$tds=$table[$i];
$name=trim($tds[0]);
//echo "I=$i Name=$name Last=$last\n";
if(substr($name,0,strlen($last))==$last)continue;
$last=$name;
$stock=intval($tds[1]);
$price=intval($tds[3]);
$thisGame[$name]=array(
'areaName'=>$name,
'basePrice'=>$price,
'stock'=>$stock,
'favor'=>array()
);
for($j=0;$j<$favorCount;$j++){
$favorStock=intval($headers[$j]);
$favorPrice=$tds[$j +3];
$thisGame[$name]['favor'][$favorStock]=intval($favorPrice);
}
}
//dump($thisGame);exit;
return $thisGame;
}
function getBuyPrice($http){
$thisGame=array();
$doc=$this->get($http);
$doc=$this->getMiddle($doc,'botan');
$table=$this->getTableData($doc);
//dump($table);exit;
for($i=1;$i<count($table);$i++){
$tds=$table[$i];
$name=$tds[0];
$stock=intval($tds[1]);
$price=intval($tds[2]);
$thisGame[$name]=array(
'areaName'=>$name,
'basePrice'=>$price,
'stock'=>$stock,
);
}
//dump($thisGame);exit;
return $thisGame;
}
function getGames($GamePage){
$doc = $this->get($GamePage);
if($doc===false)return false;
$reg='/]*>]*alt="([^"]*)"><\/a><\/td>/i';
$matchs=$this->pregMatchAll($reg,$doc);
//dump($matchs);exit;
foreach($matchs as $match){
if($match==$matchs[0])continue;
$name=$match[2];
$mts=$this->pregMatch('/(?:rmt)?\s*(\S*)/i',$name);
//dump($name);dump($mts);exit;
$name=trim($mts[1]);
$name=$this->getMiddle($name,null,' ',true);
$http=$match[1];
$doc=$this->get2($http);
$regSell='/]*>/i';
$regBuy='/]*>/i';
$mtsSell=$this->pregMatch($regSell,$doc,true);
$mtsBuy=$this->pregMatch($regBuy,$doc,true);
if($mtsSell)
$httpSell=$mtsSell[1];
else
$httpSell=false;
if($mtsBuy)
$httpBuy=$mtsBuy[1];
else
$httpBuy=false;
//dump($http);dump($mtsSell);dump($mtsBuy);exit;
if(!$mts)continue;
$games[$name]=array(
'sell'=>$httpSell,
'buy'=>$httpBuy
);
}
//dump($games);exit;
return $games;
}
}
?>
阅读(553) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~