使用C++程序获取新浪行情数据的方法
作者:邵明 时间:2022-06-16 13:14:35
在日常开发中我们经常会使用到行情数据,很多的时候我们根据一个基准数据区构造行情,但是随着时间的推移然来构造的数据与真实行情数据之间的差距越来越大。
本问以AG1309为例子来说明,如何使用C++程序来获取新浪行情数据。(说明如果合约过期获取的数据将未空,此时请更换合约信息)。
好了,在这里就不再将废话,直接给出源码供大家学习!
// HttpDataTest.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#define MAXSIZE 1024
#pragma comment(lib, "Wininet.lib")
void urlopen(_TCHAR*);
std::string GetSubBtFind(char* lpsz);
int Token(const char* pSep, char* pStr, std::vector& refvec);
int _tmain(int argc, _TCHAR* argv[])
{
urlopen(_T("http://hq.sinajs.cn/list=AG1309"));
system("pause");
return 0;
}
void urlopen(_TCHAR* url)
{
HINTERNET hSession = InternetOpen(_T("UrlTest"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if(hSession != NULL)
{
HINTERNET hHttp = InternetOpenUrl(hSession, url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);
if (hHttp != NULL)
{
wprintf_s(_T("%s\n"), url);
char Temp[MAXSIZE];
ULONG Number = 1;
while (Number > 0)
{
InternetReadFile(hHttp, Temp, MAXSIZE - 1, &Number);
Temp[Number] = '\0';
std::string str= GetSubBtFind(Temp);
;
char szpstr[1024];
strcpy(szpstr, str.c_str());
std::vector vec;
Token(",", szpstr, vec);
printf("%s\n", Temp);
for(int i=0; i
{
printf("%s\n", vec[i]);
}
}
InternetCloseHandle(hHttp);
hHttp = NULL;
}
InternetCloseHandle(hSession);
hSession = NULL;
}
}
std::string GetSubBtFind(char* lpsz)
{
std::string scrStr=lpsz;
std::string str_temp="";
int len=strlen(lpsz);
int beginPos=scrStr.find("\"");
scrStr=scrStr.substr(beginPos+1,len);
int endPos=scrStr.find("\"");
str_temp=scrStr.substr(0,endPos);
return str_temp;
}
int Token(const char* pSep, char* pStr, std::vector& refvec)
{
for(char* outer = strtok(pStr, pSep) ; NULL != outer; outer = strtok(NULL, pSep))
{
refvec.push_back(outer);
}
return 0;
}
上述代码在vs2008下运行结果如下:
标签:C++,获取数据
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
unity使用socket实现聊天室功能
2021-08-12 01:57:59
![](https://img.aspxhome.com/file/2023/5/108745_0s.jpg)
java读取文件字符集示例方法
2023-11-09 12:35:39
Java语法基础之循环结构语句详解
2023-09-06 21:37:28
![](https://img.aspxhome.com/file/2023/1/79811_0s.jpg)
C#实现递归调用的Lambda表达式
2022-10-03 05:13:29
SpringBoot+Vue项目新手快速入门指南
2023-05-20 04:56:07
java读取ftp中TXT文件的案例
2022-07-07 20:10:11
![](https://img.aspxhome.com/file/2023/1/101771_0s.jpg)
浅析Java自定义注解的用法
2022-06-08 01:52:58
![](https://img.aspxhome.com/file/2023/7/84167_0s.png)
C#重写DataGridView
2021-06-09 11:56:26
c#执行excel宏模版的方法
2022-11-15 12:04:03
使用spring容器在初始化Bean时前和后的操作
2021-07-01 05:49:24
spring data jpa 查询自定义字段,转换为自定义实体方式
2022-10-12 04:52:43
![](https://img.aspxhome.com/file/2023/4/71634_0s.png)
spring webflux自定义netty 参数解析
2023-07-26 18:38:25
![](https://img.aspxhome.com/file/2023/1/57811_0s.jpg)
Unity Shader实现玻璃材质效果
2021-10-27 05:25:29
![](https://img.aspxhome.com/file/2023/7/77227_0s.jpg)
一篇文章带你入门Java基本概念
2023-11-26 01:17:08
![](https://img.aspxhome.com/file/2023/8/60318_0s.png)
C#创建WebService接口并连接的全过程
2023-04-07 07:47:21
![](https://img.aspxhome.com/file/2023/5/100085_0s.jpg)
RocketMQ集群消费与广播消费模式
2021-10-16 07:20:45
java switch语句使用注意的四大细节
2022-07-10 10:46:04
hibernate-validator改进校验框架validator v0.4使用
2023-01-22 21:08:07
java使用淘宝API读写json实现手机归属地查询功能代码
2021-05-31 03:27:38
Java开发Oracle数据库连接JDBC Thin Driver 的三种方法
2022-05-08 09:40:50