最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java實時獲取基金收益項目源碼分享

 更新時間:2021年03月15日 14:36:49   作者:hwtl070359898  
這篇文章主要介紹了Java實時獲取基金收益項目源碼分享,主要包括JAVA爬取天天基金網(wǎng)數(shù)據(jù)使用實例、應用技巧、基本知識點總結和需要注意事項,需要的朋友可以參考下

本文章向大家介紹JAVA爬取天天基金網(wǎng)數(shù)據(jù),主要包括JAVA爬取天天基金網(wǎng)數(shù)據(jù)使用實例、應用技巧、基本知識點總結和需要注意事項,具有一定的參考價值,需要的朋友可以參考一下。

天天基金網(wǎng)網(wǎng)址:http://quote.eastmoney.com/center/gridlist.html#fund_lof

Java爬蟲實時獲取基金收益歷史記錄代碼:

首先要自己定義幾個參數(shù):基金編碼,頁數(shù),每頁顯示條數(shù) 開始時間結束時間等

(我這直接寫的靜態(tài)方法使用的 大家可以改成Test方法自行進行測試)

/**
   * httClient 請求 GET
   * 獲取基金網(wǎng)數(shù)據(jù)1
   */
  public static JSONArray testDepartmentList1(String code){
    Integer pageIndex = 1;
    Integer pageSize=20;
    String startTime="2018-1-1";
    String endTime = "2020-4-15";
    String referer = "http://fundf10.eastmoney.com/f10/jjjz_" + code + ".html";
    long time = System.currentTimeMillis();
    String url = "http://api.fund.eastmoney.com/f10/lsjz?callback=jQuery18306596328894644803_1571038362181&" +
        "fundCode=%s&pageIndex=%s&pageSize=%s&startDate=%s&endDate=%s&_=%s";
    url = String.format(url,code,pageIndex,pageSize,startTime,endTime,time);
    System.out.println("url= " + url);
    System.out.println(url);
    HttpRequest request = HttpUtil.createGet(url);
    request.header("Referer", referer);
    String str = request.execute().body();
    //獲取str的長度
    System.out.println("str=" + str);
    int length = str.length();
    System.out.println("length=" + length);
    //indexOf返回某個指定的字符串值在字符串中首次出現(xiàn)的位置
    int indexStart = str.indexOf("(");
    System.out.println(indexStart);
    //截取字符串
    str = str.substring(indexStart + 9, length - 90);
    System.out.println(str);
    //轉換為Obj類型
    JSONObject jsonObject = JSON.parseObject(str);
    System.out.println(jsonObject);
    //獲取數(shù)組
    JSONArray jsonArray = jsonObject.getJSONArray("LSJZList");
    //計算數(shù)組的長度
    int size = jsonArray.size();
    System.out.println(size);
 
    return jsonArray;
  }

通過基金編碼查詢基金名稱

(由于基金網(wǎng)url里面的信息只有基金編號跟漲跌幅日期等 沒有基金名稱 我們通過基金網(wǎng)的查詢功能自行填充基金編碼進行查詢)

/**
   * httClient 請求 GET
   * 獲取基金網(wǎng)數(shù)據(jù)2
   */
  @Test
  public static String testDepartmentList2(String code) {
    //數(shù)據(jù)鏈接
    String referer = "http://so.eastmoney.com/web/s?keyword="+code+"";
     long time = System.currentTimeMillis();
 
    String url = "http://push2.eastmoney.com/api/qt/stock/get?ut=fa5fd1943c7b386f172d6893dbfba10b&fltt" +
        "=2&fields=f59,f169,f170,f161,f163,f171,f126,f168,f164,f78,f162,f43,f46,f44,f45,f60,f47," +
        "f48,f49,f84,f116,f55,f92,f71,f50,f167,f117,f85,f84,f58,f57,f86,f172,f108,f118,f107,f164," +
        "f177&invt=2&secid=0."+code+"&cb=jQuery1124006112441213993569_1587006450385&_=1587006450403";
    url = String.format(url,code);
    System.out.println("請求url:" + url);
    //http請求
    HttpRequest request = HttpUtil.createGet(url);
 
    request.header("Referer", referer);
    String str = request.execute().body();
    //獲取str的長度
    System.out.println("str=" + str);
    int length = str.length();
    System.out.println("length=" + length);
    //indexOf返回某個指定的字符串值在字符串中首次出現(xiàn)的位置
    int i = str.indexOf("(");
    System.out.println(i);
    //截取字符串
    str = str.substring(i + 55, length - 3);
    System.out.println(str);
    //轉換為Obj類型
    JSONObject jsonObject = JSON.parseObject(str);
    System.out.println(jsonObject);
    String fundName = jsonObject.getString("f58");
    return fundName;
  }

java實時獲取基金收益

業(yè)務層實現(xiàn):(主要功能:用戶輸入基金編號查詢某個基金時如果數(shù)據(jù)庫沒有,自動從天天基金網(wǎng)爬取數(shù)據(jù)存儲到數(shù)據(jù)庫并顯示到頁面上)

顯示的數(shù)據(jù)分別有:基金編號 基金日期 基金名稱 實際價格 每日漲跌幅

@Override
  public List<FundHistory> query(String fundCode) {
    List<FundHistory> query = fundHistoryDao.query(fundCode);
    if (query.size()==0) {
      JSONArray jsonArray = testDepartmentList1(fundCode);
      System.out.println(jsonArray);
      //計算數(shù)組的長度
      int size = jsonArray.size();
      System.out.println(size);
      //for循環(huán)遍歷
      for (int j = 0; j < size; j++) {
        JSONObject jsonObject1 = jsonArray.getJSONObject(j);
        //獲取凈值日期
        String date = jsonObject1.getString("FSRQ");
        //獲取單位凈值
        Double unit = jsonObject1.getDouble("DWJZ");
        //獲取累積凈值
        Double Accumulates = jsonObject1.getDouble("LJJZ");
        //獲取日增長率
        String growthRate = jsonObject1.getString("JZZZL");
        //創(chuàng)建時間
        DateTime dateTime = new DateTime();
        //獲取創(chuàng)建時間
        String datetime = String.valueOf(dateTime);
        FundHistory fundHistory = new FundHistory();
        fundHistory.setFundCode(fundCode);
        fundHistory.setDate(date);
        fundHistory.setUnit(unit);
        fundHistory.setAccumulates(Accumulates);
        fundHistory.setGrowthRate(growthRate);
        fundHistory.setCreateTime(datetime);
        fundHistoryDao.saveFundHistory(fundHistory);
      }
      FundHistory fundHistory = new FundHistory();
      fundHistory.setFundCode(fundCode);
      //獲取基金名稱
      String fundName = testDepartmentList2(fundCode);
      fundHistory.setFundName(fundName);
      fundHistoryDao.updateFundHistory(fundHistory);
      List<FundHistory> query2 = fundHistoryDao.query(fundCode);
      FundHistory fundHistory1 = query2.get(0);
      fundDao.saveFund2(fundHistory1);
      return query2;
    }
    return query;
  }

controller層

 /**
   * 基金頁面數(shù)據(jù)交互
   * @param
   * @return
   */
  @RequestMapping("/enquiryfund")
  @ResponseBody
  public Result enquiryfund(String fundCode,String fundName){
    Result result = new Result<>();
    if (fundCode!=""){
      List<FundHistory> query = fundHistoryService.query(fundCode);
      if (query==null){
        List<FundHistory> query2 = fundHistoryService.query(fundCode);
        result.setData(query2);
        return result;
      }
      result.setData(query);
      return result;
    }else if (fundName!=""){
      List<FundHistory> fundHistories = fundHistoryService.query2(fundName);
      result.setData(fundHistories);
      return result;
    }
    return result;
  }

java實時獲取基金收益項目運行效果如圖:

(根據(jù)基金編號進行查詢基金 如果數(shù)據(jù)庫沒有則自動從天天基金網(wǎng)拉取數(shù)據(jù)并顯示到頁面上 共拉取20條歷史數(shù)據(jù))

/**
 * httClient 請求 GET
 * 獲取基金網(wǎng)數(shù)據(jù)1
 */
 
 
 
public static JSONArray testDepartmentList1(String code){
  Integer pageIndex = 1;
  Integer pageSize=20;
  String startTime="2018-1-1";
  String endTime = "2020-4-15";
  String referer = "http://fundf10.eastmoney.com/f10/jjjz_" + code + ".html";
  long time = System.currentTimeMillis();
  String url = "http://api.fund.eastmoney.com/f10/lsjz?callback=jQuery18306596328894644803_1571038362181&" +
      "fundCode=%s&pageIndex=%s&pageSize=%s&startDate=%s&endDate=%s&_=%s";
  url = String.format(url,code,pageIndex,pageSize,startTime,endTime,time);
  System.out.println("url= " + url);
  System.out.println(url);
  HttpRequest request = HttpUtil.createGet(url);
  request.header("Referer", referer);
  String str = request.execute().body();
  //獲取str的長度
System.out.println("str=" + str);
  int length = str.length();
  System.out.println("length=" + length);
  //indexOf返回某個指定的字符串值在字符串中首次出現(xiàn)的位置
int indexStart = str.indexOf("(");
  System.out.println(indexStart);
  //截取字符串
str = str.substring(indexStart + 9, length - 90);
  System.out.println(str);
  //轉換為Obj類型
JSONObject jsonObject = JSON.parseObject(str);
  System.out.println(jsonObject);
  //獲取數(shù)組
JSONArray jsonArray = jsonObject.getJSONArray("LSJZList");
  //計算數(shù)組的長度
int size = jsonArray.size();
  System.out.println(size);
 
  return jsonArray;
}

這就是我為大家分享的Java實時獲取基金收益項目源碼,希望對大家有幫助哈~~~

到此這篇關于Java實時獲取基金收益項目源碼分享的文章就介紹到這了,更多相關Java獲取基金收益內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • 淺談JDK14性能管理工具之jmap和jhat

    淺談JDK14性能管理工具之jmap和jhat

    我們在寫代碼的過程中,經(jīng)常會遇到內存泄露的問題,比如某個集合中的對象沒有被回收,或者內存出現(xiàn)不明原因的增長。這些都是需要我們來定位的問題,我們可以使用jmap和jhat來對java程序中的內存對象進行分析。
    2021-06-06
  • Spring Boot 如何自定義返回錯誤碼錯誤信息

    Spring Boot 如何自定義返回錯誤碼錯誤信息

    這篇文章主要介紹了Spring Boot 如何自定義返回錯誤碼錯誤信息的相關知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-08-08
  • Java SSL與TLS客戶端證書配置方式

    Java SSL與TLS客戶端證書配置方式

    這篇文章主要介紹了Java SSL與TLS客戶端證書配置方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • 在 Spring Boot 中集成 MinIO 對象存儲

    在 Spring Boot 中集成 MinIO 對象存儲

    MinIO 是一個開源的對象存儲服務器,專注于高性能、分布式和兼容S3 API的存儲解決方案,本文將介紹如何在 Spring Boot 應用程序中集成 MinIO,以便您可以輕松地將對象存儲集成到您的應用中,需要的朋友可以參考下
    2023-09-09
  • springboot中使用groovy的示例代碼

    springboot中使用groovy的示例代碼

    Groovy就是一種繼承了動態(tài)語言的優(yōu)良特性并運行在JVM上的編程語言,Groovy支持動態(tài)輸入,閉包,元編程,運算符重載等等語法,這篇文章主要介紹了springboot中使用groovy的相關知識,需要的朋友可以參考下
    2022-09-09
  • 理解HashSet里為什么value不是null

    理解HashSet里為什么value不是null

    你有沒有想過Java中HashSet的Value為什么要存PRESENT而不是Null?帶著這個疑問來看下邊的文章尋找答案吧
    2021-09-09
  • java中線程池的關閉問題

    java中線程池的關閉問題

    這篇文章主要介紹了java中線程池的關閉問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • Springboot使用redis實現(xiàn)接口Api限流的示例代碼

    Springboot使用redis實現(xiàn)接口Api限流的示例代碼

    本文主要介紹了Springboot使用redis實現(xiàn)接口Api限流的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-07-07
  • Java深入理解代碼塊的使用細節(jié)

    Java深入理解代碼塊的使用細節(jié)

    所謂代碼塊是指用"{}"括起來的一段代碼,根據(jù)其位置和聲明的不同,可以分為普通代碼塊、構造塊、靜態(tài)塊、和同步代碼塊。如果在代碼塊前加上?synchronized關鍵字,則此代碼塊就成為同步代碼塊
    2022-05-05
  • Mybatis Properties 配置優(yōu)先級詳解

    Mybatis Properties 配置優(yōu)先級詳解

    這篇文章主要介紹了Mybatis Properties 配置優(yōu)先級,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07

最新評論

鲁甸县| 潮安县| 巴楚县| 化德县| 寻甸| 磐石市| 贵南县| 留坝县| 龙川县| 潞西市| 英超| 海南省| 勐海县| 仪征市| 中西区| 杭州市| 太和县| 孟州市| 余干县| 瑞昌市| 房山区| 巴楚县| 临漳县| 红河县| 隆尧县| 嘉禾县| 洪湖市| 丽水市| 卢湾区| 惠州市| 绵竹市| 南澳县| 东城区| 大关县| 龙胜| 石河子市| 张家界市| 浮梁县| 宁海县| 略阳县| 如皋市|