使用C++程序獲取新浪行情數(shù)據(jù)的方法
在日常開發(fā)中我們經(jīng)常會(huì)使用到行情數(shù)據(jù),很多的時(shí)候我們根據(jù)一個(gè)基準(zhǔn)數(shù)據(jù)區(qū)構(gòu)造行情,但是隨著時(shí)間的推移然來構(gòu)造的數(shù)據(jù)與真實(shí)行情數(shù)據(jù)之間的差距越來越大。
本問以AG1309為例子來說明,如何使用C++程序來獲取新浪行情數(shù)據(jù)。(說明如果合約過期獲取的數(shù)據(jù)將未空,此時(shí)請(qǐng)更換合約信息)。
好了,在這里就不再將廢話,直接給出源碼供大家學(xué)習(xí)!
// HttpDataTest.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
#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下運(yùn)行結(jié)果如下:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家熟練應(yīng)用C++程序抓取數(shù)據(jù)有所幫助
相關(guān)文章
淺談使用Rapidxml 庫(kù)遇到的問題和分析過程(分享)
下面小編就為大家?guī)硪黄獪\談使用Rapidxml 庫(kù)遇到的問題和分析過程(分享)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05C++ 關(guān)于 CMFCPropertyGridCtrl 的使用方法
這篇文章主要介紹了C++ 關(guān)于 CMFCPropertyGridCtrl 的使用方法的相關(guān)資料,需要的朋友可以參考下2015-06-06C語言數(shù)據(jù)的存儲(chǔ)和取出詳細(xì)講解
這篇文章主要介紹了C語言數(shù)據(jù)的存儲(chǔ)和取出詳細(xì)講解,作者使用圖文代碼實(shí)例講解,有感興趣的同學(xué)可以學(xué)習(xí)研究下2021-02-02C++實(shí)現(xiàn)簡(jiǎn)單猜數(shù)字小游戲
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)簡(jiǎn)單猜數(shù)字小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01有關(guān)C++中類類型轉(zhuǎn)換操作符總結(jié)(必看篇)
下面小編就為大家?guī)硪黄嘘P(guān)C++中類類型轉(zhuǎn)換操作符總結(jié)(必看篇)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-01-01