PHP抓取基金凈值并計算

富國基金凈值

最近用螞蟻聚寶的慧定投買了富國中證500指數(shù)增強(qiáng)這只基金,想要計算下每周扣款之后能拿到多少份額。所以寫了個計算頁面,目標(biāo)是用PHP爬取富國基金公司官網(wǎng)上的富國中證500指數(shù)增強(qiáng)這只基金的當(dāng)天凈值,然后按照實際扣款金額計算出所得份額。

  • 實際代碼如下:
<?php 
  //抓取整個頁面
  $url="http://www.fullgoal.com.cn/"; 
  $contents = file_get_contents($url); 
  //依據(jù)抓取 到的頁面按照table進(jìn)行過濾
  $preg1='/<table[^>]*>(.*?) <\/table>/si';
  $res2="";
  preg_match_all($preg1,$contents,$res2);
  $res3=$res2[0][9];
  //echo $res3;
  //將過濾后的table再次按照td進(jìn)行過濾
  $res4="";
  preg_match_all('/<td[^>]*>(.*?) <\/td>/si',$res3,$res4);
  $res5=$res4[0][0];
  //將給字符串按照空格拆分成數(shù)組
  $res6=explode(" ",$res5);
  //得到最終的基金凈值和時間
  $funToday=$res6[27];
  $funValueToday=$res6[45];
  //對數(shù)據(jù)進(jìn)行去空格和去html標(biāo)簽操作
  $fund1=trim($funValueToday);
  $fund2=strip_tags($fund1);
?>
<html>
    <head>
        <meta charset="utf-8"  />
        <title>慧定投計算器</title>
        <style type="text/css"> 
        /*全局樣式設(shè)置*/  
        *{  
            margin:0px;  
            padding:0px;  
        }    
        body {  
            width:600px;  
            margin:10px auto;  
            font-size:14px;  
        }
        input:hover {
            border:1px solid #363636;
            box-shadow: 2px 3px 2px #888888;
        }   
        span {
            padding:20px;
            text-align: left;
        }
        /*局部設(shè)置*/
        .div1 {
            width: 600px;
            margin: 0px auto;
            text-align: center;
            padding-top: 10px;
        }
        .divP p {
            padding-top: 10px;
            width:300px;
            font-size:20px;
            font-style: inherit;
            text-align: center;
            margin:0px auto;
        }
        .divP h2{
            color: rgb(218,88,77);
            font-size: 2em;
        }
        .titlename {
            color: rgb(215,88,77);
        }
        
        input {
            width: 250px;
            height: 30px;
            margin:5px auto;
            text-align: left;
        }
        .subM {
            font-weight: bold;
            font-size: 22px;
            width: 200px;
            height: 30px;
            text-align: center;
            margin-top: 20px;
        }
        
        </style>
    </head>
    <body>
        <div class="div1">
            <div class="img1">
                <img src="http://upload-images.jianshu.io/upload_images/4167376-d6f538037602f6cd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" /><br />
            </div>
            <form action="huidingtou-fuguo.php" method="post" class="form1">
                <div class="divP">
                    <p class="titlename"><h2>慧定投計算器</h2></p>
                    <p><h3>富國中證500指數(shù)增強(qiáng)</h3></p>
                    <p><?php echo "凈值日期:".$funToday;?></p>
                <p><strong>慧定投實際扣款額:</strong></p><input type="text"  name="ShijikouK"  class="zongFe"value= <?php echo @$_POST['ShijikouK'];?>>><br />
                <input type="submit" value="計   算" class="subM" />
                </div>
            </form>
        </div>
    </body>
</html>
<?php
    //抓取頁面輸入的數(shù)據(jù)
    //實際扣款額
    $ShijikouK=$_REQUEST['ShijikouK'];
    //計算凈申購額
    $jingshenE=$ShijikouK/(1+0.0015);
    //計算基金份額
    $fundShare=$jingshenE/$fund2;
        echo "<p style='font-size: 20px;text-align:center;padding-top:15px;'><strong>當(dāng)天凈值:</strong>".$fund2."元/份</p><p style='font-size: 20px;text-align:center;padding-top:15px;'><strong>凈申購額:</strong>".round($jingshenE,2)."元</p><p style='font-size: 20px;text-align:center;padding-top:15px;'><strong>基金份額:</strong>".round($fundShare,2)."份</p>";
?>

最后效果:

PS:整體功能還很簡陋,之后慢慢豐富吧T_T

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 這個品種風(fēng)險太高,完全不適合剛?cè)腴T的理財小白,只適有比較長的投資經(jīng)驗和比較全面的投資知識的理財達(dá)人玩。對理財小白而...
    朱進(jìn)偉西農(nóng)閱讀 3,737評論 7 20
  • 第六章投資基金的重要原則正確的投資理念:長期投資選擇時機(jī):該出手時當(dāng)出手基金定投:最適合工薪階層的投資方式信息分析...
    你在學(xué)校閱讀 12,469評論 7 52
  • 指數(shù)型基金:被動型投資策略貨幣市場基金:代替銀行儲蓄ETF和LOF:兩種交易渠道選擇保本型基金:在股票市場熊市行情...
    你在學(xué)校閱讀 5,918評論 1 22
  • 掘金分級B---牛市里分級B最好的投資策略:不動如山! 牛市里力最推崇的一種投資策略,這種投資策略只適合那些風(fēng)險承...
    朱進(jìn)偉西農(nóng)閱讀 1,614評論 2 7
  • 你想知道每件事情為什么至于如此,如果你理清了這件事情所有的脈絡(luò),十分理性地分析好了前因后果,那么你很可能能夠得到為...
    愛讀君閱讀 455評論 0 0

友情鏈接更多精彩內(nèi)容