Last active
April 13, 2022 15:04
-
-
Save daixianceng/4cd50f7319b8191ee2c222ea964f8ceb to your computer and use it in GitHub Desktop.
A股市场股票数据 - NodeJs接口
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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