Skip to content

Instantly share code, notes, and snippets.

@daixianceng
Created April 13, 2022 15:05
Show Gist options
  • Select an option

  • Save daixianceng/d3c8b5cd18579b4137f4097385fe6d03 to your computer and use it in GitHub Desktop.

Select an option

Save daixianceng/d3c8b5cd18579b4137f4097385fe6d03 to your computer and use it in GitHub Desktop.
A股市场股票数据 - NodeJs接口
const fetch = require('node-fetch-retry');
const iconv = require('iconv-lite');
module.exports = async function (list) {
const response = await fetch('https://hq.sinajs.cn/list=' + list, {
method: 'GET',
headers: {
Referer: 'https://finance.sina.com.cn',
},
retry: 3,
pause: 10000,
});
const orignal = await response.arrayBuffer();
const result = await iconv.decode(Buffer.from(orignal), 'gbk');
return result.split('\n').map(parseHqStr).filter(Boolean);
};
function parseHqStr(str) {
const result = str.match(/^var hq_str_(\w+)="([^"]+)";?$/);
if (result) {
return [result[1], ...result[2].split(',')];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment