Commit 437d9244 authored by rlgy's avatar rlgy

市值爬取

parent 03d47dd2
...@@ -58,7 +58,9 @@ class CoinService ...@@ -58,7 +58,9 @@ class CoinService
/** /**
* 爬取币种的实时行情,默认eos * 爬取币种的实时行情,默认eos
*
* @param string $sid * @param string $sid
* @return bool|array
*/ */
public static function quotation($sid = 'eos') public static function quotation($sid = 'eos')
{ {
...@@ -66,9 +68,21 @@ class CoinService ...@@ -66,9 +68,21 @@ class CoinService
$ch = new Curl(); $ch = new Curl();
try { try {
$content = $ch->get($url, true); $content = $ch->get($url, true);
//价格 价格美元 价格btc 最高价 最低价 涨幅(跌幅) $result = [
$result = ['price' => '', 'dollar' => '', 'btc' => '', 'high' => '', 'low' => '', 'change' => '']; 'price' => '',//价格
//价格与涨幅 'dollar' => '',//价格美元
'btc' => '',//价格btc
'high' => '',//最高价
'low' => '',//最低价
'change' => '',//涨幅(跌幅)
'rank' => '',//流通市值排名
'circulate_value_rmb' => '',//流通市值人民币
'circulate_value_usd' => '',//流通市值美元
'circulate_value_btc' => '',//流通市值btc
'publish_count' => '',//发行总量
'circulate_count' => '',//流通总量
];
//价格与涨幅 //价格与涨幅
$pattern = '/<div class=coinprice>(.*?)<span class=(tags-red|tags-green)>(.*?)<\/span><\/div>/is'; $pattern = '/<div class=coinprice>(.*?)<span class=(tags-red|tags-green)>(.*?)<\/span><\/div>/is';
preg_match_all($pattern, $content, $matchs, PREG_SET_ORDER); preg_match_all($pattern, $content, $matchs, PREG_SET_ORDER);
...@@ -87,6 +101,20 @@ class CoinService ...@@ -87,6 +101,20 @@ class CoinService
$result['dollar'] = $matchs[0][1]; $result['dollar'] = $matchs[0][1];
$result['btc'] = $matchs[0][3]; $result['btc'] = $matchs[0][3];
//爬取市值与排名
$pattern = '/<div class=value>(.*?)<span class=tag-marketcap>(.*?)<\/span><\/div><div class=sub>(.*?)<\/div><div class=sub>(.*?)<\/div>/is';
preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
$result['circulate_value_rmb'] = $matches[0][1];
$result['rank'] = $matches[0][2];
$result['circulate_value_usd'] = $matches[0][3];
$result['circulate_value_btc'] = $matches[0][4];
//爬取流通总量,发行总量
$pattern = '/<div class=tit>流通量<\/div><div class=value>(.*?)<\/div><div class=tit>总发行量<\/div><div class=value>(.*?)<\/div>/is';
preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
$result['circulate_count'] = $matches[0][1];
$result['publish_count'] = $matches[0][2];
$result = array_map(function ($value) { $result = array_map(function ($value) {
return trim($value); return trim($value);
}, $result); }, $result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment