Skip to content

Instantly share code, notes, and snippets.

@daixianceng
Last active April 13, 2022 15:04
Show Gist options
  • Select an option

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

Select an option

Save daixianceng/4cd50f7319b8191ee2c222ea964f8ceb 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://qt.gtimg.cn/q=' + list, {
retry: 3,
pause: 10000,
});
const orignal = await response.arrayBuffer();
const result = await iconv.decode(Buffer.from(orignal), 'gbk');
return result.split('\n').map(parseQtStr).filter(Boolean);
};
function parseQtStr(str) {
const result = str.match(/^v_(\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