且慢基金爬虫——自动更新x-sign的投资组合爬取

@

一、网页分析

1、打开网页

参照上期蛋卷基金爬虫,我们打开且慢基金的网页,随意打开一个投资组合页面,例如:

https://qieman.com/portfolios/ZH000193

在这里插入图片描述
我们发现一个以组合ID命名的文件,这应该就是我们要的内容了,我们点开它。
在这里插入图片描述
d(ŐдŐ๑)怎么是空的!
在这里插入图片描述
但是我们观察Network里,明明这个文件有191B啊,我们试着右键把响应内容复制出来。
在这里插入图片描述

{"poCode":"ZH000193","poName":"绿巨人","driveMode":"DR","poType":"4","poDesc":"超级英雄绿巨人,权益资产配置型FOF,发车信号关注订阅号:望京博格投基 ","poRichDesc":"计划将自己的基金组合Open起来,如果未来业绩好,多半原因归因于市场给予我在3000点以下的建仓期! 组合调整,订阅号:望京博格聊基 (强烈建议关注)","poStatus":"1","visibility":"1","establishedOn":"2016-05-27","runningDays":1843,"ceasedOn":null,"ceasedComment":null,"risk5Level":4,"risk5LevelName":"中高风险","poManagers":[{"poManagerId":136,"poManagerName":"望京博格","poManagerDesc":"资产配置投资实践","poManagerRichDesc":null,"poManagerAvatarUrl":"https://asset.qieman.com/pomgr/pomgr_136.png","verified":true}],"nav":"1.7087","navDate":"2021-06-16","dailyReturn":"-0.0112","weeklyReturn":"-0.0256","monthlyReturn":"0.0266","quarterlyReturn":"-0.0008","halfYearlyReturn":"0.0128","yearlyReturn":"0.1872","fromSetupReturn":"0.7087","annualCompoundedReturn":"0.1119","maxDrawdown":"0.2058","sharpe":"0.5540","volatility":"0.1660","personalBuyAmount":0,"totalBuyAmount":0,"totalBuyerCount":0,"tags":null,"recommendHoldingPeriod":null,"recommendInvestmentWays":null,"promotionDesc":null,"accumulatedCost":0,"accumulatedProfit":0,"accumulatedDays":1843,"canDeposit":true,"cannotDepositReason":null,"canWithdraw":true,"cannotWithdrawReason":null,"personalHighestBuyAmount":"10000000.00","personalLowestBuyAmount":"100.00","personalHighestAipAmount":"10000000.00","personalLowestAipAmount":"100.00","composition":[{"prodType":"1","fundCode":"110031","prodCode":"110031","prodName":"易方达恒生国企ETF联接A","fundName":"易方达恒生国企ETF联接A","percent":"0.2144","nav":"1.1288","navDate":"2021-06-16","fundType":"7","fundInvestType":"1","riskLevel":3,"risk5Level":3,"isQdii":true,"isPeriod":false,"isLof":false,"isIndex":true,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0091","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY110031-V20210406","fundCode":"110031","name":"110031产品资料概要(20210406)","url":"https://cdn-disclosure.yingmi.cn/CN_50110000_110031_FA010080_20210006_110031_20210406_090000_01.pdf"},"fundTypeAEvent":null},{"prodType":"1","fundCode":"004642","prodCode":"004642","prodName":"南方房地产ETF联接A","fundName":"南方房地产ETF联接A","percent":"0.1512","nav":"0.8333","navDate":"2021-06-16","fundType":"6","fundInvestType":"1","riskLevel":3,"risk5Level":3,"isQdii":false,"isPeriod":false,"isLof":false,"isIndex":true,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"0.0007","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY004642-V20210331","fundCode":"004642","name":"004642产品资料概要(20210331)","url":"https://cdn-disclosure.yingmi.cn/CN_50020000_004642_FA010080_20210003_004642_20210331_090000_01.pdf"},"fundTypeAEvent":null},{"prodType":"1","fundCode":"001475","prodCode":"001475","prodName":"易方达国防军工混合","fundName":"易方达国防军工混合","percent":"0.2834","nav":"1.4660","navDate":"2021-06-16","fundType":"3","fundInvestType":"3","riskLevel":3,"risk5Level":4,"isQdii":false,"isPeriod":false,"isLof":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0161","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY001475-V20210427","fundCode":"001475","name":"001475产品资料概要(20210427)","url":"https://cdn-disclosure.yingmi.cn/CN_50110000_001475_FA010080_20210001_001475_20210427_090000_01.pdf"},"fundTypeAEvent":null},{"prodType":"1","fundCode":"501021","prodCode":"501021","prodName":"华宝香港中国中小盘(LOF)A","fundName":"华宝香港中国中小盘(LOF)A","percent":"0.2162","nav":"1.8256","navDate":"2021-06-16","fundType":"7","fundInvestType":"1","riskLevel":3,"risk5Level":3,"isQdii":true,"isPeriod":false,"isLof":true,"isIndex":true,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0217","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY501021-V20210513","fundCode":"501021","name":"501021产品资料概要(20210513)","url":"https://cdn-disclosure.yingmi.cn/CN_50220000_501021_FA010080_20210297_501021_20210513_103701_01.pdf"},"fundTypeAEvent":null},{"prodType":"1","fundCode":"006327","prodCode":"006327","prodName":"易方达中证海外联接人民币A","fundName":"易方达中证海外联接人民币A","percent":"0.1348","nav":"1.4401","navDate":"2021-06-15","fundType":"7","fundInvestType":"1","riskLevel":3,"risk5Level":4,"isQdii":true,"isPeriod":false,"isLof":false,"isIndex":true,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0017","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY006327-V20210406","fundCode":"006327","name":"006327产品资料概要(20210406)","url":"https://cdn-disclosure.yingmi.cn/CN_50110000_006327_FA010080_20210001_006327_20210406_090000_01.pdf"},"fundTypeAEvent":null}],"adjustInfo":{"adjustmentId":166776,"comment":"2018年下半年,由于医药极速下跌同时找不到更好的行业,所以纳入沪深300指数,如果以现在的结果回顾这次调仓,会发现那次是错误的.... 现在望京博格觉得未来三年角度地产应该跑赢沪深300,因为地产目前低估,低估也有低估的道路,但是未来中国城市化进程,尤其是准一线城市的发展收益的还是大型地产公司。","adjustedOn":"2020-09-07","details":[{"fundCode":"110020","prodCode":"110020","prodType":"1","fromPercent":"0.1826","toPercent":"0.0000","fundName":"易方达沪深300ETF联接A","prodName":"易方达沪深300ETF联接A","fundType":"6","fundInvestType":"1","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":true,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY110020-V20210406","fundCode":"110020","name":"110020产品资料概要(20210406)","url":"https://cdn-disclosure.yingmi.cn/CN_50110000_110020_FA010080_20210002_110020_20210406_090000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"110031","prodCode":"110031","prodType":"1","fromPercent":"0.2175","toPercent":"0.2172","fundName":"易方达恒生国企ETF联接A","prodName":"易方达恒生国企ETF联接A","fundType":"7","fundInvestType":"1","isQdii":true,"isLof":false,"isPeriod":false,"isIndex":true,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY110031-V20210406","fundCode":"110031","name":"110031产品资料概要(20210406)","url":"https://cdn-disclosure.yingmi.cn/CN_50110000_110031_FA010080_20210006_110031_20210406_090000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"501021","prodCode":"501021","prodType":"1","fromPercent":"0.1911","toPercent":"0.1908","fundName":"华宝香港中国中小盘(LOF)A","prodName":"华宝香港中国中小盘(LOF)A","fundType":"7","fundInvestType":"1","isQdii":true,"isLof":true,"isPeriod":false,"isIndex":true,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY501021-V20210513","fundCode":"501021","name":"501021产品资料概要(20210513)","url":"https://cdn-disclosure.yingmi.cn/CN_50220000_501021_FA010080_20210297_501021_20210513_103701_01.pdf"},"fundTypeAEvent":null},{"fundCode":"001475","prodCode":"001475","prodType":"1","fromPercent":"0.2612","toPercent":"0.2609","fundName":"易方达国防军工混合","prodName":"易方达国防军工混合","fundType":"3","fundInvestType":"3","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY001475-V20210427","fundCode":"001475","name":"001475产品资料概要(20210427)","url":"https://cdn-disclosure.yingmi.cn/CN_50110000_001475_FA010080_20210001_001475_20210427_090000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"006327","prodCode":"006327","prodType":"1","fromPercent":"0.1476","toPercent":"0.1488","fundName":"易方达中证海外联接人民币A","prodName":"易方达中证海外联接人民币A","fundType":"7","fundInvestType":"1","isQdii":true,"isLof":false,"isPeriod":false,"isIndex":true,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY006327-V20210406","fundCode":"006327","name":"006327产品资料概要(20210406)","url":"https://cdn-disclosure.yingmi.cn/CN_50110000_006327_FA010080_20210001_006327_20210406_090000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"004642","prodCode":"004642","prodType":"1","fromPercent":"0.0000","toPercent":"0.1823","fundName":"南方房地产ETF联接A","prodName":"南方房地产ETF联接A","fundType":"6","fundInvestType":"1","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":true,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY004642-V20210331","fundCode":"004642","name":"004642产品资料概要(20210331)","url":"https://cdn-disclosure.yingmi.cn/CN_50020000_004642_FA010080_20210003_004642_20210331_090000_01.pdf"},"fundTypeAEvent":null}]},"sigAdjustment":null,"extra":{"agreements":[{"id":"AGREEMENT04-V20200511","name":"盈米宝服务协议","url":"https://asset2.qieman.com/agreement/agreement04-3767ba77-fbf9-49ec-abe8-e69fb2a61a57.pdf"},{"id":"AGREEMENT06-V20200511","name":"且慢平台服务协议","url":"https://asset2.qieman.com/agreement/agreement06-63d980cd-858f-4ebb-bd7d-33b9e99578ef.pdf"}],"aipAgreements":[{"id":"AGREEMENT07-V20200511","name":"基金约定交易服务协议","url":"https://asset2.qieman.com/agreement/agreement07-211340f0-7c0d-4699-a63f-ef7d727904ea.pdf"}],"benchmarks":[{"code":"hs300","name":"沪深300"}]},"useRealPerformance":false,"riskLevel":3,"prodSummaries":[{"id":"SUMMARY110031-V20210406","fundCode":"110031","name":"110031产品资料概要(20210406)","url":"https://cdn-disclosure.yingmi.cn/CN_50110000_110031_FA010080_20210006_110031_20210406_090000_01.pdf"},{"id":"SUMMARY004642-V20210331","fundCode":"004642","name":"004642产品资料概要(20210331)","url":"https://cdn-disclosure.yingmi.cn/CN_50020000_004642_FA010080_20210003_004642_20210331_090000_01.pdf"},{"id":"SUMMARY001475-V20210427","fundCode":"001475","name":"001475产品资料概要(20210427)","url":"https://cdn-disclosure.yingmi.cn/CN_50110000_001475_FA010080_20210001_001475_20210427_090000_01.pdf"},{"id":"SUMMARY501021-V20210513","fundCode":"501021","name":"501021产品资料概要(20210513)","url":"https://cdn-disclosure.yingmi.cn/CN_50220000_501021_FA010080_20210297_501021_20210513_103701_01.pdf"},{"id":"SUMMARY006327-V20210406","fundCode":"006327","name":"006327产品资料概要(20210406)","url":"https://cdn-disclosure.yingmi.cn/CN_50110000_006327_FA010080_20210001_006327_20210406_090000_01.pdf"}],"fundTypeAEvents":[],"followCount":29905,"canWeeklyAip":false} 

我们观察到其实是有返回很多信息的,但是为什么点进去看不到呢?
原来是且慢基金网站有反爬虫的校验。

2、分析x-sign

我们观察一下请求标头。
在这里插入图片描述
我们把这些内容全部复制到爬虫的header里,然后逐个删除,看看哪个才是起关键作用的。
我们发现,只要有x-sign就行了,如果没有正确的x-sign就会返回空值。

有x-sign:

在这里插入图片描述

无x-sign:

在这里插入图片描述
但是这个x-sign貌似是一日一更新的,也就是昨天的x-sign今天就失效了,如果我们手动每天更新,又很麻烦。
我们发现这个x-sign的前13位是一个时间戳,后32位则是通过时间戳形成的一个加密。

1621566508433|32A579E8505A7B5A7BB5CB69D6AA6BDD

3、自动更新x-sign

网络上的教程基本都是通过阅读JavaScript来破译x-sign的加密算法,但是偏偏且慢把js写得很繁琐,内嵌了一个虚拟机来实现加密,破译这条路子有些复杂,那我们还能怎么办呢?

我们可以模拟浏览器的访问操作来获取x-sign! (๑•̀ㅂ•́)و✧

这里我们用到selenium库,需要安装一个webdriver,详细教程网上好多,这里不赘述。
我们从performance中找出所有带x-sign的内容。

#by concyclics # -*- coding:UTF-8 -*- from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities import json import time def getX_sign(): url = 'https://qieman.com' d = DesiredCapabilities.CHROME d['loggingPrefs'] = {'performance': 'ALL'} browser=webdriver.Chrome() browser.get(url) time.sleep(1) info = browser.get_log('performance') #print(info) for i in info: dic_info = json.loads(i["message"]) info = dic_info["message"]['params'] if 'request' in info: #print(info['request']) if 'headers' in info['request']: #print(info['request']['headers']) if 'x-sign' in info['request']['headers']: # print(info['request']['headers']['x-sign']) print(info['request']['headers']['x-sign']) #browser.close() return False if __name__=='__main__': getX_sign() 

发现selenium帮我们打开了chrome。
在这里插入图片描述
并返回了3条x-sign。
在这里插入图片描述
这是因为对于每一个请求,网站都会重新算一个x-sign,但是我们只要一个就好,而且每天一个,所以我们可以根据当前已有的x-sign的前13位时间戳,计算它是否是今天的x-sign,不是再去获取,毕竟selenium比requests慢不少,同时我们可以隐藏弹窗。
具体代码如下:

from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities import json import time import datetime xsign='1623897696198395318DDBC26EFC3AA40DC4A6D28E8AC' def getX_sign(): url = 'https://qieman.com' d = DesiredCapabilities.CHROME d['loggingPrefs'] = {'performance': 'ALL'} option = webdriver.ChromeOptions() option.add_argument('headless') browser = webdriver.Chrome(options=option) browser.get(url) info = browser.get_log('performance') #print(info) for i in info: dic_info = json.loads(i["message"]) info = dic_info["message"]['params'] if 'request' in info: #print(info['request']) if 'headers' in info['request']: #print(info['request']['headers']) if 'x-sign' in info['request']['headers']: browser.close() # print(info['request']['headers']['x-sign']) return info['request']['headers']['x-sign'] browser.close() return False def getXsign(): global xsign t=int(xsign[0:13])//1000 last=time.localtime(t) last=datetime.datetime(last[0],last[1],last[2]) today=time.localtime(time.time()) today=datetime.datetime(today[0],today[1],today[2]) diff=(today-last).days #print(t,last,today,diff) if diff==0: return xsign try: getX_sign() except Exception: return False xsign=getX_sign() return xsign if __name__=='__main__': print(getXsign()) 

二、json分析

我们发现基金的基本信息和历史净值放在这两个地方:

1、基本信息

观察json

{"poCode":"ZH001798","poName":"东方进取1号","driveMode":"DR","poType":"1","poDesc":"本组合是激进配置,力求大幅跑赢沪深300指数,争取超过99%的投资者,并超越85-90%的公募基金。\n由于长年都是高仓位运行,风险较大,购买前请认真阅读基金组合使用说明书","poRichDesc":"从2019年开始,组合会加强逆向投资的运用,有的逆向操作并不会马上带来收益,请给3个月左右的观察期。","poStatus":"1","visibility":"1","establishedOn":"2016-07-26","runningDays":1786,"ceasedOn":null,"ceasedComment":null,"risk5Level":3,"risk5LevelName":"中风险","poManagers":[{"poManagerId":612,"poManagerName":"东方财之道","poManagerDesc":"理财之道,与你同行!","poManagerRichDesc":null,"poManagerAvatarUrl":"https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoo8sp4FZJ8xdkTibPu0fUk9IdfhEn0yfJhVYIDA36ZkDHjEs2vbT1jw7xPLmN2YbaR4dQJIWtOfSQ/132","verified":true}],"nav":"2.2379","navDate":"2021-06-16","dailyReturn":"-0.0196","weeklyReturn":"-0.0235","monthlyReturn":"0.0195","quarterlyReturn":"0.0268","halfYearlyReturn":"0.0831","yearlyReturn":"0.3166","fromSetupReturn":"1.2379","annualCompoundedReturn":"0.1790","maxDrawdown":"0.2778","sharpe":"0.8855","volatility":"0.1795","personalBuyAmount":0,"totalBuyAmount":0,"totalBuyerCount":0,"tags":null,"recommendHoldingPeriod":null,"recommendInvestmentWays":null,"promotionDesc":null,"accumulatedCost":0,"accumulatedProfit":0,"accumulatedDays":1786,"canDeposit":true,"cannotDepositReason":null,"canWithdraw":true,"cannotWithdrawReason":null,"personalHighestBuyAmount":"532481.00","personalLowestBuyAmount":"100.00","personalHighestAipAmount":"532481.00","personalLowestAipAmount":"100.00","composition":[{"prodType":"1","fundCode":"519736","prodCode":"519736","prodName":"交银新成长混合","fundName":"交银新成长混合","percent":"0.1343","nav":"4.4730","navDate":"2021-06-16","fundType":"3","fundInvestType":"3","riskLevel":3,"risk5Level":3,"isQdii":false,"isPeriod":false,"isLof":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0189","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":"100000.00","tags":["限大额"],"existProdSummary":true,"prodSummary":{"id":"SUMMARY519736-V20210528","fundCode":"519736","name":"519736产品资料概要(20210528)","url":"https://cdn-disclosure.yingmi.cn/CN_50480000_519736_FA010080_20210001_519736_20210528_090000_01.pdf"},"fundTypeAEvent":null},{"prodType":"1","fundCode":"005760","prodCode":"005760","prodName":"富国周期优势混合A","fundName":"富国周期优势混合A","percent":"0.1434","nav":"2.9355","navDate":"2021-06-16","fundType":"3","fundInvestType":"3","riskLevel":3,"risk5Level":3,"isQdii":false,"isPeriod":false,"isLof":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0187","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":"2000000.00","tags":["限大额"],"existProdSummary":true,"prodSummary":{"id":"SUMMARY005760-V20210311","fundCode":"005760","name":"005760产品资料概要(20210311)","url":"https://cdn-disclosure.yingmi.cn/CN_50100000_005760_FA010070_20210004_005760_20210311_090000_01.pdf"},"fundTypeAEvent":null},{"prodType":"1","fundCode":"005267","prodCode":"005267","prodName":"嘉实价值精选股票","fundName":"嘉实价值精选股票","percent":"0.0767","nav":"2.1811","navDate":"2021-06-16","fundType":"1","fundInvestType":"1","riskLevel":3,"risk5Level":3,"isQdii":false,"isPeriod":false,"isLof":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0169","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":"50000000.00","tags":["限大额"],"existProdSummary":true,"prodSummary":{"id":"SUMMARY005267-V20210609","fundCode":"005267","name":"005267产品资料概要(20210609)","url":"https://cdn-disclosure.yingmi.cn/CN_50080000_005267_FA010080_20210006_005267_20210609_090000_01.pdf"},"fundTypeAEvent":null},{"prodType":"1","fundCode":"009076","prodCode":"009076","prodName":"工银圆兴混合","fundName":"工银圆兴混合","percent":"0.1878","nav":"1.7762","navDate":"2021-06-16","fundType":"3","fundInvestType":"3","riskLevel":3,"risk5Level":3,"isQdii":false,"isPeriod":false,"isLof":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0237","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":"100000.00","tags":["限大额"],"existProdSummary":true,"prodSummary":{"id":"SUMMARY009076-V20210422","fundCode":"009076","name":"009076产品资料概要(20210422)","url":"https://cdn-disclosure.yingmi.cn/CN_50470000_009076_FA010080_20210002_009076_20210422_000000_01.pdf"},"fundTypeAEvent":null},{"prodType":"1","fundCode":"001605","prodCode":"001605","prodName":"国富沪港深成长精选股票","fundName":"国富沪港深成长精选股票","percent":"0.1742","nav":"2.6880","navDate":"2021-06-16","fundType":"1","fundInvestType":"1","riskLevel":3,"risk5Level":4,"isQdii":false,"isPeriod":false,"isLof":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0240","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY001605-V20210330","fundCode":"001605","name":"001605产品资料概要(20210330)","url":"https://cdn-disclosure.yingmi.cn/CN_50420000_001605_FA010080_20200002_001605_20210330_000000_01.pdf"},"fundTypeAEvent":null},{"prodType":"1","fundCode":"163415","prodCode":"163415","prodName":"兴全商业模式优选混合","fundName":"兴全商业模式优选混合","percent":"0.0689","nav":"3.8480","navDate":"2021-06-16","fundType":"3","fundInvestType":"3","riskLevel":3,"risk5Level":3,"isQdii":false,"isPeriod":false,"isLof":true,"isIndex":false,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0121","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":"100000.00","tags":["限大额"],"existProdSummary":true,"prodSummary":{"id":"SUMMARY163415-V20210210","fundCode":"163415","name":"163415产品资料概要(20210210)","url":"https://cdn-disclosure.yingmi.cn/CN_50310000_163415_FA010080_20210001_163415_20210210_090000_01.pdf"},"fundTypeAEvent":null},{"prodType":"1","fundCode":"004424","prodCode":"004424","prodName":"汇添富文体娱乐混合","fundName":"汇添富文体娱乐混合","percent":"0.1026","nav":"2.8411","navDate":"2021-06-16","fundType":"3","fundInvestType":"3","riskLevel":3,"risk5Level":3,"isQdii":false,"isPeriod":false,"isLof":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0194","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY004424-V20210421","fundCode":"004424","name":"004424产品资料概要(20210421)","url":"https://cdn-disclosure.yingmi.cn/CN_50460000_004424_FA010080_20210216_004424_20210421_000000_01.pdf"},"fundTypeAEvent":null},{"prodType":"1","fundCode":"166009","prodCode":"166009","prodName":"中欧新动力混合(LOF)A","fundName":"中欧新动力混合(LOF)A","percent":"0.1121","nav":"3.4311","navDate":"2021-06-16","fundType":"3","fundInvestType":"3","riskLevel":3,"risk5Level":3,"isQdii":false,"isPeriod":false,"isLof":true,"isIndex":false,"isEtf":false,"valDisBy":"nav","yearlyRoe":null,"unitYield":null,"dailyReturn":"-0.0142","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY166009-V20201105","fundCode":"166009","name":"166009产品资料概要(20201105)","url":"https://cdn-disclosure.yingmi.cn/CN_50570000_166009_FA010080_20200007_166009_20201105_090000_01.pdf"},"fundTypeAEvent":null}],"adjustInfo":{"adjustmentId":251680,"comment":"继续减少波动大、风控较弱的基金,增加均衡和价值型风格的基金,增加组合防守力。","adjustedOn":"2021-03-23","details":[{"fundCode":"163411","prodCode":"163411","prodType":"1","fromPercent":"0.1028","toPercent":"0.0000","fundName":"兴全精选","prodName":"兴全精选","fundType":"3","fundInvestType":"3","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":"100000.00","tags":["限大额"],"existProdSummary":true,"prodSummary":{"id":"SUMMARY163411-V20210210","fundCode":"163411","name":"163411产品资料概要(20210210)","url":"https://cdn-disclosure.yingmi.cn/CN_50310000_163411_FA010080_20210002_163411_20210210_090000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"519736","prodCode":"519736","prodType":"1","fromPercent":"0.1321","toPercent":"0.1325","fundName":"交银新成长混合","prodName":"交银新成长混合","fundType":"3","fundInvestType":"3","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":"100000.00","tags":["限大额"],"existProdSummary":true,"prodSummary":{"id":"SUMMARY519736-V20210528","fundCode":"519736","name":"519736产品资料概要(20210528)","url":"https://cdn-disclosure.yingmi.cn/CN_50480000_519736_FA010080_20210001_519736_20210528_090000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"519778","prodCode":"519778","prodType":"1","fromPercent":"0.0654","toPercent":"0.0000","fundName":"交银经济新动力混合","prodName":"交银经济新动力混合","fundType":"3","fundInvestType":"3","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY519778-V20201119","fundCode":"519778","name":"519778产品资料概要(20201119)","url":"https://cdn-disclosure.yingmi.cn/CN_50480000_519778_FA010080_20200002_519778_20201119_090000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"001605","prodCode":"001605","prodType":"1","fromPercent":"0.1798","toPercent":"0.1787","fundName":"国富沪港深成长精选股票","prodName":"国富沪港深成长精选股票","fundType":"1","fundInvestType":"1","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY001605-V20210330","fundCode":"001605","name":"001605产品资料概要(20210330)","url":"https://cdn-disclosure.yingmi.cn/CN_50420000_001605_FA010080_20200002_001605_20210330_000000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"004424","prodCode":"004424","prodType":"1","fromPercent":"0.1285","toPercent":"0.1000","fundName":"汇添富文体娱乐混合","prodName":"汇添富文体娱乐混合","fundType":"3","fundInvestType":"3","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY004424-V20210421","fundCode":"004424","name":"004424产品资料概要(20210421)","url":"https://cdn-disclosure.yingmi.cn/CN_50460000_004424_FA010080_20210216_004424_20210421_000000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"005275","prodCode":"005275","prodType":"1","fromPercent":"0.1043","toPercent":"0.0000","fundName":"中欧创新成长灵活配置混合A","prodName":"中欧创新成长灵活配置混合A","fundType":"3","fundInvestType":"3","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY005275-V20210324","fundCode":"005275","name":"005275产品资料概要(20210324)","url":"https://cdn-disclosure.yingmi.cn/CN_50570000_005275_FA010080_20210002_005275_20210324_090000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"005760","prodCode":"005760","prodType":"1","fromPercent":"0.1092","toPercent":"0.1400","fundName":"富国周期优势混合A","prodName":"富国周期优势混合A","fundType":"3","fundInvestType":"3","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":"2000000.00","tags":["限大额"],"existProdSummary":true,"prodSummary":{"id":"SUMMARY005760-V20210311","fundCode":"005760","name":"005760产品资料概要(20210311)","url":"https://cdn-disclosure.yingmi.cn/CN_50100000_005760_FA010070_20210004_005760_20210311_090000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"009076","prodCode":"009076","prodType":"1","fromPercent":"0.1779","toPercent":"0.1785","fundName":"工银圆兴混合","prodName":"工银圆兴混合","fundType":"3","fundInvestType":"3","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":"100000.00","tags":["限大额"],"existProdSummary":true,"prodSummary":{"id":"SUMMARY009076-V20210422","fundCode":"009076","name":"009076产品资料概要(20210422)","url":"https://cdn-disclosure.yingmi.cn/CN_50470000_009076_FA010080_20210002_009076_20210422_000000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"163415","prodCode":"163415","prodType":"1","fromPercent":"0.0000","toPercent":"0.0700","fundName":"兴全商业模式优选混合","prodName":"兴全商业模式优选混合","fundType":"3","fundInvestType":"3","isQdii":false,"isLof":true,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":"100000.00","tags":["限大额"],"existProdSummary":true,"prodSummary":{"id":"SUMMARY163415-V20210210","fundCode":"163415","name":"163415产品资料概要(20210210)","url":"https://cdn-disclosure.yingmi.cn/CN_50310000_163415_FA010080_20210001_163415_20210210_090000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"166009","prodCode":"166009","prodType":"1","fromPercent":"0.0000","toPercent":"0.1200","fundName":"中欧新动力混合(LOF)A","prodName":"中欧新动力混合(LOF)A","fundType":"3","fundInvestType":"3","isQdii":false,"isLof":true,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":null,"tags":[],"existProdSummary":true,"prodSummary":{"id":"SUMMARY166009-V20201105","fundCode":"166009","name":"166009产品资料概要(20201105)","url":"https://cdn-disclosure.yingmi.cn/CN_50570000_166009_FA010080_20200007_166009_20201105_090000_01.pdf"},"fundTypeAEvent":null},{"fundCode":"005267","prodCode":"005267","prodType":"1","fromPercent":"0.0000","toPercent":"0.0803","fundName":"嘉实价值精选股票","prodName":"嘉实价值精选股票","fundType":"1","fundInvestType":"1","isQdii":false,"isLof":false,"isPeriod":false,"isIndex":false,"isEtf":false,"valDisBy":"nav","onSale":true,"canBuy":true,"canAllot":true,"personalHighestBuyAmount":"50000000.00","tags":["限大额"],"existProdSummary":true,"prodSummary":{"id":"SUMMARY005267-V20210609","fundCode":"005267","name":"005267产品资料概要(20210609)","url":"https://cdn-disclosure.yingmi.cn/CN_50080000_005267_FA010080_20210006_005267_20210609_090000_01.pdf"},"fundTypeAEvent":null}]},"sigAdjustment":null,"extra":{"agreements":[{"id":"AGREEMENT04-V20200511","name":"盈米宝服务协议","url":"https://asset2.qieman.com/agreement/agreement04-3767ba77-fbf9-49ec-abe8-e69fb2a61a57.pdf"},{"id":"AGREEMENT06-V20200511","name":"且慢平台服务协议","url":"https://asset2.qieman.com/agreement/agreement06-63d980cd-858f-4ebb-bd7d-33b9e99578ef.pdf"}],"aipAgreements":[{"id":"AGREEMENT07-V20200511","name":"基金约定交易服务协议","url":"https://asset2.qieman.com/agreement/agreement07-211340f0-7c0d-4699-a63f-ef7d727904ea.pdf"}],"benchmarks":[{"code":"hs300","name":"沪深300"}]},"useRealPerformance":false,"riskLevel":3,"prodSummaries":[{"id":"SUMMARY519736-V20210528","fundCode":"519736","name":"519736产品资料概要(20210528)","url":"https://cdn-disclosure.yingmi.cn/CN_50480000_519736_FA010080_20210001_519736_20210528_090000_01.pdf"},{"id":"SUMMARY005760-V20210311","fundCode":"005760","name":"005760产品资料概要(20210311)","url":"https://cdn-disclosure.yingmi.cn/CN_50100000_005760_FA010070_20210004_005760_20210311_090000_01.pdf"},{"id":"SUMMARY005267-V20210609","fundCode":"005267","name":"005267产品资料概要(20210609)","url":"https://cdn-disclosure.yingmi.cn/CN_50080000_005267_FA010080_20210006_005267_20210609_090000_01.pdf"},{"id":"SUMMARY009076-V20210422","fundCode":"009076","name":"009076产品资料概要(20210422)","url":"https://cdn-disclosure.yingmi.cn/CN_50470000_009076_FA010080_20210002_009076_20210422_000000_01.pdf"},{"id":"SUMMARY001605-V20210330","fundCode":"001605","name":"001605产品资料概要(20210330)","url":"https://cdn-disclosure.yingmi.cn/CN_50420000_001605_FA010080_20200002_001605_20210330_000000_01.pdf"},{"id":"SUMMARY163415-V20210210","fundCode":"163415","name":"163415产品资料概要(20210210)","url":"https://cdn-disclosure.yingmi.cn/CN_50310000_163415_FA010080_20210001_163415_20210210_090000_01.pdf"},{"id":"SUMMARY004424-V20210421","fundCode":"004424","name":"004424产品资料概要(20210421)","url":"https://cdn-disclosure.yingmi.cn/CN_50460000_004424_FA010080_20210216_004424_20210421_000000_01.pdf"},{"id":"SUMMARY166009-V20201105","fundCode":"166009","name":"166009产品资料概要(20201105)","url":"https://cdn-disclosure.yingmi.cn/CN_50570000_166009_FA010080_20200007_166009_20201105_090000_01.pdf"}],"fundTypeAEvents":[],"followCount":2423,"canWeeklyAip":false} 

获取如下内容

基金编号: ZH001798
基金名: 东方进取1号
日期: 2021-06-16
净值: 2.2379
最大回撤: 0.2778
年化波动率: 0.1795
夏普率: 0.8855

获取方法

def getfund(code): url='https://qieman.com/pmdj/v1/pomodels/'+code page=requests.get(url,headers=header).text print(page) if(page==''): raise ValueError('请设置x-sign或检查code') items=json.loads(page) value=items.get("nav") date=items.get("navDate") name=items.get("poName") found=items.get('establishedOn') print("基金编号:",code,'\n基金名:',name,"\n日期:",date,"净值:",value) maxdown=items.get("maxDrawdown") volatility=items.get("volatility") sharpe=items.get("sharpe") print('最大回撤:',maxdown,'年化波动率:',volatility,'夏普率:',sharpe,'\n') 

2、历史净值

观察json

省略了一部分内容省的页面过大

[{"navDate":1469462400000,"nav":1,"dailyReturn":null},{"navDate":1469548800000,"nav":1.000068248,"dailyReturn":0.000068248},{"navDate":1469635200000,"nav":1.0001278702,"dailyReturn":0.0000596182},{"navDate":1469721600000,"nav":1.0001789091,"dailyReturn":0.0000510323},{"navDate":1469980800000,"nav":0.9998294726,"dailyReturn":-0.0003493739},{"navDate":1470067200000,"nav":1.0025945807,"dailyReturn":0.0027655796},{"navDate":1606838400000,"nav":2.0272375269,"dailyReturn":-0.001792889},{"navDate":1606924800000,"nav":2.0274959278,"dailyReturn":0.0001274645},{"navDate":1607011200000,"nav":2.0458947043,"dailyReturn":0.0090746306},{"navDate":1607270400000,"nav":2.0463292921,"dailyReturn":0.0002124195},{"navDate":1607356800000,"nav":2.0577638818,"dailyReturn":0.0055878542},{"navDate":1607443200000,"nav":2.0347857009,"dailyReturn":-0.011166578},{"navDate":1607529600000,"nav":2.0417437154,"dailyReturn":0.0034195319},{"navDate":1607616000000,"nav":2.0238078002,"dailyReturn":-0.0087846065},{"navDate":1607875200000,"nav":2.0514214588,"dailyReturn":0.0136444077},{"navDate":1607961600000,"nav":2.0639874194,"dailyReturn":0.0061254895},{"navDate":1608048000000,"nav":2.0661708106,"dailyReturn":0.001057851},{"navDate":1608134400000,"nav":2.0796735919,"dailyReturn":0.0065351719},{"navDate":1608220800000,"nav":2.0835812392,"dailyReturn":0.0018789715},{"navDate":1608480000000,"nav":2.1364171246,"dailyReturn":0.0253582075},{"navDate":1608566400000,"nav":2.1073761155,"dailyReturn":-0.0135933235},{"navDate":1608652800000,"nav":2.1375027608,"dailyReturn":0.0142958084},{"navDate":1608739200000,"nav":2.1365259381,"dailyReturn":-0.0004569925},{"navDate":1608825600000,"nav":2.1629761936,"dailyReturn":0.0123800301},{"navDate":1609084800000,"nav":2.1663276441,"dailyReturn":0.0015494625},{"navDate":1609171200000,"nav":2.1458781069,"dailyReturn":-0.009439725},{"navDate":1609257600000,"nav":2.1887280922,"dailyReturn":0.0199685085},{"navDate":1609344000000,"nav":2.2244625861,"dailyReturn":0.0163266026},{"navDate":1609689600000,"nav":2.287720432,"dailyReturn":0.0284373611},{"navDate":1609776000000,"nav":2.3308133895,"dailyReturn":0.0188366362},{"navDate":1609862400000,"nav":2.3368039417,"dailyReturn":0.0025701552},{"navDate":1609948800000,"nav":2.3789822451,"dailyReturn":0.0180495687},{"navDate":1610035200000,"nav":2.3559565776,"dailyReturn":-0.0096787892},{"navDate":1610294400000,"nav":2.3430487306,"dailyReturn":-0.0054788136},{"navDate":1610380800000,"nav":2.402415483,"dailyReturn":0.0253373955},{"navDate":1610467200000,"nav":2.3776468039,"dailyReturn":-0.0103099065},{"navDate":1610553600000,"nav":2.3346334884,"dailyReturn":-0.0180907086},{"navDate":1610640000000,"nav":2.3360489395,"dailyReturn":0.0006062841},{"navDate":1610899200000,"nav":2.3791311654,"dailyReturn":0.0184423473},{"navDate":1610985600000,"nav":2.3414372679,"dailyReturn":-0.0158435558},{"navDate":1611072000000,"nav":2.3980017455,"dailyReturn":0.0241580154},{"navDate":1611158400000,"nav":2.4411536678,"dailyReturn":0.0179949503},{"navDate":1611244800000,"nav":2.4756562231,"dailyReturn":0.0141337089},{"navDate":1611504000000,"nav":2.515378047,"dailyReturn":0.0160449676},{"navDate":1611590400000,"nav":2.4522068528,"dailyReturn":-0.025113996},{"navDate":1611676800000,"nav":2.4530369588,"dailyReturn":0.0003385138},{"navDate":1611763200000,"nav":2.3776303579,"dailyReturn":-0.0307400998},{"navDate":1611849600000,"nav":2.370206742,"dailyReturn":-0.003122275},{"navDate":1612108800000,"nav":2.4228489985,"dailyReturn":0.0222099851},{"navDate":1612195200000,"nav":2.4805775569,"dailyReturn":0.0238267257},{"navDate":1612281600000,"nav":2.4801865181,"dailyReturn":-0.0001576402},{"navDate":1612368000000,"nav":2.4625676838,"dailyReturn":-0.0071038344},{"navDate":1612454400000,"nav":2.4515541952,"dailyReturn":-0.0044723598},{"navDate":1612713600000,"nav":2.4945188898,"dailyReturn":0.0175254925},{"navDate":1612800000000,"nav":2.5478495132,"dailyReturn":0.0213791219},{"navDate":1612886400000,"nav":2.59274591,"dailyReturn":0.0176212907},{"navDate":1613577600000,"nav":2.5747773332,"dailyReturn":-0.0069303269},{"navDate":1613664000000,"nav":2.5507233459,"dailyReturn":-0.0093421621},{"navDate":1613923200000,"nav":2.459978347,"dailyReturn":-0.0355761824},{"navDate":1614009600000,"nav":2.4464948727,"dailyReturn":-0.0054811353},{"navDate":1614096000000,"nav":2.3612128688,"dailyReturn":-0.0348588525},{"navDate":1614182400000,"nav":2.369032257,"dailyReturn":0.0033115982},{"navDate":1614268800000,"nav":2.3021227711,"dailyReturn":-0.0282433832},{"navDate":1614528000000,"nav":2.3598349365,"dailyReturn":0.0250691084},{"navDate":1614614400000,"nav":2.3308341788,"dailyReturn":-0.0122893162},{"navDate":1614700800000,"nav":2.3639321685,"dailyReturn":0.0142000619},{"navDate":1614787200000,"nav":2.2666446817,"dailyReturn":-0.0411549401},{"navDate":1614873600000,"nav":2.2630960867,"dailyReturn":-0.0015655718},{"navDate":1615132800000,"nav":2.1640958267,"dailyReturn":-0.0437454956},{"navDate":1615219200000,"nav":2.1254021909,"dailyReturn":-0.0178798163},{"navDate":1615305600000,"nav":2.161142572,"dailyReturn":0.0168158202},{"navDate":1615392000000,"nav":2.218893609,"dailyReturn":0.0267224559},{"navDate":1615478400000,"nav":2.2096722924,"dailyReturn":-0.0041558174},{"navDate":1615737600000,"nav":2.1533106973,"dailyReturn":-0.0255067665},{"navDate":1615824000000,"nav":2.1795742906,"dailyReturn":0.0121968434},{"navDate":1615910400000,"nav":2.2049408137,"dailyReturn":0.0116382925},{"navDate":1615996800000,"nav":2.2329361656,"dailyReturn":0.0126966455},{"navDate":1616083200000,"nav":2.1806740789,"dailyReturn":-0.0234050966},{"navDate":1616342400000,"nav":2.1878094036,"dailyReturn":0.003272073},{"navDate":1616428800000,"nav":2.1491341725,"dailyReturn":-0.0176776053},{"navDate":1616515200000,"nav":2.1058034823,"dailyReturn":-0.0201619288},{"navDate":1616601600000,"nav":2.117700396,"dailyReturn":0.005649584},{"navDate":1616688000000,"nav":2.1707032989,"dailyReturn":0.0250285182},{"navDate":1616947200000,"nav":2.180790661,"dailyReturn":0.0046470478},{"navDate":1617033600000,"nav":2.2022844774,"dailyReturn":0.0098559742},{"navDate":1617120000000,"nav":2.1884362707,"dailyReturn":-0.0062881098},{"navDate":1617206400000,"nav":2.2229272844,"dailyReturn":0.0157605749},{"navDate":1617292800000,"nav":2.2377969435,"dailyReturn":0.0066892242},{"navDate":1617638400000,"nav":2.2307743456,"dailyReturn":-0.0031381748},{"navDate":1617724800000,"nav":2.2168451458,"dailyReturn":-0.0062441097},{"navDate":1617811200000,"nav":2.2237471271,"dailyReturn":0.0031134251},{"navDate":1617897600000,"nav":2.1979353608,"dailyReturn":-0.0116073298},{"navDate":1618156800000,"nav":2.1516557929,"dailyReturn":-0.0210559276},{"navDate":1618243200000,"nav":2.1522895713,"dailyReturn":0.0002945538},{"navDate":1618329600000,"nav":2.1776986316,"dailyReturn":0.0118055956},{"navDate":1618416000000,"nav":2.170050868,"dailyReturn":-0.0035118558},{"navDate":1618502400000,"nav":2.1862609822,"dailyReturn":0.0074699236},{"navDate":1618761600000,"nav":2.2339603498,"dailyReturn":0.021817783},{"navDate":1618848000000,"nav":2.2373120606,"dailyReturn":0.0015003448},{"navDate":1618934400000,"nav":2.2351708204,"dailyReturn":-0.0009570593},{"navDate":1619020800000,"nav":2.2401798093,"dailyReturn":0.0022409871},{"navDate":1619107200000,"nav":2.2561986577,"dailyReturn":0.0071506976},{"navDate":1619366400000,"nav":2.249289921,"dailyReturn":-0.0030621137},{"navDate":1619452800000,"nav":2.2562983418,"dailyReturn":0.003115837},{"navDate":1619539200000,"nav":2.2718944076,"dailyReturn":0.0069122356},{"navDate":1619625600000,"nav":2.2717779952,"dailyReturn":-0.0000512402},{"navDate":1619712000000,"nav":2.2573003172,"dailyReturn":-0.0063728401},{"navDate":1620230400000,"nav":2.2423364831,"dailyReturn":-0.0066290843},{"navDate":1620316800000,"nav":2.2012259373,"dailyReturn":-0.0183337988},{"navDate":1620576000000,"nav":2.1915840366,"dailyReturn":-0.0043802413},{"navDate":1620662400000,"nav":2.1815185699,"dailyReturn":-0.0045927815},{"navDate":1620748800000,"nav":2.1901812464,"dailyReturn":0.0039709387},{"navDate":1620835200000,"nav":2.1657499657,"dailyReturn":-0.0111549128},{"navDate":1620921600000,"nav":2.1952320378,"dailyReturn":0.0136128697},{"navDate":1621180800000,"nav":2.2390204153,"dailyReturn":0.0199470383},{"navDate":1621267200000,"nav":2.2455808657,"dailyReturn":0.0029300538},{"navDate":1621353600000,"nav":2.2406850115,"dailyReturn":-0.0021802173},{"navDate":1621440000000,"nav":2.2464126404,"dailyReturn":0.0025561955},{"navDate":1621526400000,"nav":2.2324377407,"dailyReturn":-0.0062209852},{"navDate":1621785600000,"nav":2.2476425486,"dailyReturn":0.0068108542},{"navDate":1621872000000,"nav":2.2982736042,"dailyReturn":0.0225262935},{"navDate":1621958400000,"nav":2.2996809443,"dailyReturn":0.0006123467},{"navDate":1622044800000,"nav":2.312744502,"dailyReturn":0.0056805957},{"navDate":1622131200000,"nav":2.2954824768,"dailyReturn":-0.0074638704},{"navDate":1622390400000,"nav":2.3150482421,"dailyReturn":0.008523596},{"navDate":1622476800000,"nav":2.3272722645,"dailyReturn":0.0052802452},{"navDate":1622563200000,"nav":2.3081015095,"dailyReturn":-0.0082374354},{"navDate":1622649600000,"nav":2.2875912705,"dailyReturn":-0.0088861945},{"navDate":1622736000000,"nav":2.2995691657,"dailyReturn":0.0052360294},{"navDate":1622995200000,"nav":2.3012769253,"dailyReturn":0.0007426433},{"navDate":1623081600000,"nav":2.2820410905,"dailyReturn":-0.0083587658},{"navDate":1623168000000,"nav":2.2917587404,"dailyReturn":0.004258315},{"navDate":1623254400000,"nav":2.3011851644,"dailyReturn":0.0041131834},{"navDate":1623340800000,"nav":2.2915991739,"dailyReturn":-0.0041656754},{"navDate":1623686400000,"nav":2.2825830378,"dailyReturn":-0.0039344298},{"navDate":1623772800000,"nav":2.2379386467,"dailyReturn":-0.019558715}] 

我们发现这个json是一个列表,而且时间不是用标明日期的字符串而是时间戳展现的,所以我们要写一个时间戳转时间的函数,这里用到time和datetime库。

时间戳转换函数

import time import datetime def qieman_to_date(s): s=int(s) s/=1000 day=datetime.datetime.utcfromtimestamp(s).strftime('%Y-%m-%d') return day 

获取方法

def gethistory(code,size=10): url='https://qieman.com/pmdj/v1/pomodels/'+code+'/nav-history' page=requests.get(url,headers=header).text items=json.loads(page) for item in items[-1:-size-1:-1]: print('日期:',qieman_to_date(item.get('navDate')),'净值:',item.get('nav')) print('\n') 

这里我们从列表中读出最后的size项来,省的内容过多。

3、测试

在这里插入图片描述

三、完整代码

#by concyclics import requests import time import json import datetime from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities qieman=['ZH001798','ZH012926','ZH039471','ZH010246','ZH006498','ZH000193','ZH009664','ZH030684','ZH017252','ZH007973','ZH037807','ZH007974','ZH017409','ZH035411','ZH043108','ZH043126'] #x-sign记得每天更新 header={ 'x-sign':'1623897696198395318DDBC26EFC3AA40DC4A6D28E8AC' } #1621566508433」32A579E8505A7B5A7BB5CB69D6AA6BDD #前13位为时间戳,后32位未知 #且慢的时间戳转日期 def qieman_to_date(s): s=int(s) s/=1000 day=datetime.datetime.utcfromtimestamp(s).strftime('%Y-%m-%d') return day def getfund(code): url='https://qieman.com/pmdj/v1/pomodels/'+code page=requests.get(url,headers=header).text #print(page) if(page==''): raise ValueError('请设置x-sign或检查code') items=json.loads(page) value=items.get("nav") date=items.get("navDate") name=items.get("poName") found=items.get('establishedOn') print("基金编号:",code,'\n基金名:',name,"\n日期:",date,"净值:",value) maxdown=items.get("maxDrawdown") volatility=items.get("volatility") sharpe=items.get("sharpe") print('最大回撤:',maxdown,'年化波动率:',volatility,'夏普率:',sharpe,'\n') #获取历史净值 def gethistory(code,size=10): url='https://qieman.com/pmdj/v1/pomodels/'+code+'/nav-history' page=requests.get(url,headers=header).text items=json.loads(page) for item in items[-1:-size-1:-1]: print('日期:',qieman_to_date(item.get('navDate')),'净值:',item.get('nav')) print('\n') xsign='1623897696198395318DDBC26EFC3AA40DC4A6D28E8AC' def updateXsign(): url = 'https://qieman.com' d = DesiredCapabilities.CHROME d['loggingPrefs'] = {'performance': 'ALL'} option = webdriver.ChromeOptions() option.add_argument('headless') browser = webdriver.Chrome(options=option) browser.get(url) info = browser.get_log('performance') #print(info) for i in info: dic_info = json.loads(i["message"]) info = dic_info["message"]['params'] if 'request' in info: #print(info['request']) if 'headers' in info['request']: #print(info['request']['headers']) if 'x-sign' in info['request']['headers']: # print(info['request']['headers']['x-sign']) header['x-sign']=info['request']['headers']['x-sign'] browser.close() if __name__=='__main__': updateXsign() getfund(qieman[0]) gethistory(qieman[0]) 

四、这是我们基金爬虫的项目仓库欢迎来star!也欢迎follow我的GitHub和Gitee以及关注我的CSDN

原文链接:https://www.cnblogs.com/concyclics/p/14909871.html

原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/2072

(0)
上一篇 2022年7月30日 21:28
下一篇 2022年7月30日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

优速盾注册领取大礼包www.cdnb.net
/sitemap.xml