之前一直想收集股票或基金的数据,用来做量化交易的分析,近期发现Google Doc的表格有强大的功能,可以定义脚本来执行收集数据,下面是操作流程
- 登录Google Doc :https://docs.google.com/
- 创建电子表格
- 在菜单栏打开脚本编辑器
- 编写脚本,例如我写的是收集芯片ETF每日价格的脚本
const url = 'http://hq.sinajs.cn/list=sh512760'
var response = UrlFetchApp.fetch(url);
console.log(response.getContentText())
Logger.log(response);
eval(response.getContentText("GBK"))
const sh513330 = hq_str_sh512760.split(',')
// sh513330[0],sh513330[1]
const removed = sh513330.splice(11,18)
Logger.log(sh513330)
Logger.log(removed)
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[1]; sheet.appendRow(sh513330);- 在脚本编辑器中部署触发器,右下角有个添加触发器的按钮
- 通过宏导入脚本
到此就设置完毕了,当然你可以将脚本更完善,实现监控通知等功能。