|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
不客气,稍加分析并简化,代码参考如下【新增1个sheet,用于输出历史数据】:
适当改造,可以用于批量获取数据。如果不想输出"收盘价","涨幅",删除url中的【,f62,f63】,并修改 index = [0,1,6,5,10,4,9,3,8,2,7]
- async function 资金流向(){
- let gpdm = '0.127033';//股票代码,前缀【0.】表示深圳,【1.】表示上海
- let lmt = '0'; //天数,0不限制天数,1只取一天最新数据
- let url = 'https://push2his.eastmoney.com/api/qt/stock/fflow/daykline/get?cb=jQuery112305_17245';
- url += '&fields1=f1,f3&fields2=f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63';
- url += `&lmt=${lmt}&secid=${gpdm}`;
- let promise = await fetch(url);
- let res = await promise.text();
- let arrStr = JSON.parse(res.match(/\(([^)]+)\)/)[1]).data;
- let arr = [["日期","收盘价","涨幅","主力净流入净额","主力净流入占比","超大单净流入净额","超大单净流入占比",
- "大单净流入净额","大单净流入占比","中单净流入净额","中单净流入占比","小单净流入净额","小单净流入占比"]];
- let index = [0,11,12,1,6,5,10,4,9,3,8,2,7];//字段顺序索引
- arr = arr.concat(arrStr['klines'].map((x, i) => x.split(',').map((y,j,a) => a[index[j]])))
- Sheets(2).Activate();//激活第2张表格
- Sheets(2).Name = arrStr['name']+'_历史数据' //表格重命名
- Range('A1').Resize(arr.length, arr[0].length).Value2 = arr;
- Range("A1:M1").HorizontalAlignment = xlHAlignCenter;
- Range("A1:M1").WrapText = true;
- }
复制代码
|
评分
-
2
查看全部评分
-
|