" />

最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用C++程序獲取新浪行情數(shù)據(jù)的方法

 更新時間:2022年04月27日 08:11:14   作者:邵明  
這篇文章介紹了在一定的周期范圍內(nèi)去抓取新浪中行情數(shù)據(jù),通過更新數(shù)據(jù)來緩解構(gòu)造模擬數(shù)據(jù)與真實數(shù)據(jù)差異性,感興趣的朋友可以了解一下

在日常開發(fā)中我們經(jīng)常會使用到行情數(shù)據(jù),很多的時候我們根據(jù)一個基準數(shù)據(jù)區(qū)構(gòu)造行情,但是隨著時間的推移然來構(gòu)造的數(shù)據(jù)與真實行情數(shù)據(jù)之間的差距越來越大。

本問以AG1309為例子來說明,如何使用C++程序來獲取新浪行情數(shù)據(jù)。(說明如果合約過期獲取的數(shù)據(jù)將未空,此時請更換合約信息)。
好了,在這里就不再將廢話,直接給出源碼供大家學習!

// 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下運行結(jié)果如下:

以上就是本文的全部內(nèi)容,希望對大家熟練應用C++程序抓取數(shù)據(jù)有所幫助

相關(guān)文章

最新評論

阜宁县| 普格县| 石首市| 稻城县| 麻江县| 洞口县| 集贤县| 凤阳县| 临西县| 凤阳县| 娄底市| 德化县| 沙田区| 济源市| 巴青县| 镶黄旗| 驻马店市| 延吉市| 博白县| 阜平县| 金湖县| 宁陵县| 呈贡县| 大丰市| 买车| 马关县| 和平区| 襄垣县| 达拉特旗| 淮阳县| 朝阳县| 海安县| 舒兰市| 大竹县| 峨眉山市| 萝北县| 纳雍县| 讷河市| 湾仔区| 灵璧县| 朝阳区|