腾讯股票行情获取源代码

#include"acsy/monitor/stock_data.h"
#include<avhttp/avhttp.hpp>
#include"acsy/util/publictools.h"
#include<fstream>




namespace acsy
{
namespace monitor
{
StockData::StockData()
{
m_mem = 0;
}
int StockData::main()
{
std::string aa = "aa";
std::cout << aa << std::endl;
// deal_request();
return 0;
}
void StockData::deal_request(std::vector<std::string> vec_secucode)
{
std::string cshi = "";
boost::asio::io_service io;
avhttp::http_stream h(io);
boost::system::error_code ec;
std::string link;//"http://qt.gtimg.cn/q=sz000858"
std::string jys1 = "sz";
std::string jys2 = "sh";
for (int i = 0; i < vec_secucode.size(); i++)
{
int stockNum = atoi(vec_secucode[i].c_str());
if (stockNum < 600000)
{
link = "http://qt.gtimg.cn/q=" + jys1 + vec_secucode[i];
}
else if (stockNum >= 600000)
{
link = "http://qt.gtimg.cn/q=" + jys2 + vec_secucode[i];
}
// 打开url.
h.open(link, ec);
if (ec)
{ // 打开失败处理...
std::cout << "Error: " << ec.message() << std::endl;
return;
}
// boost::array<char, 1024> buf;
char buf[512];
// 循环读取数据.
std::string filename = "e://stock//test01.txt";
while (!ec)
{
std::size_t bytes_transferred = h.read_some(boost::asio::buffer(buf,511), ec);    // 将下载的数据打印到屏幕.
buf[bytes_transferred] = '\0';
// std::cout.write(buf.data(), bytes_transferred);
std::cout << buf << std::endl;
std::ofstream fout(filename, std::ios::app);
fout << buf << std::endl;
std::string temp = buf;
cshi += temp;
}
parse(cshi);
cshi = "";
std::cout.flush();
h.close(ec); // 关闭.
io.run();
}

}
void StockData::parse(std::string &buf)
{
std::vector < std::string> vec_stinfo;
acsy::util::StringSpliter *ss; 
ss = nullptr;
ss->splitAll(buf, '~', &vec_stinfo);
/*for (auto &m : vec_stinfo)
{
std::cout << m << std::endl;
}*/
for (int i = 0; i < vec_stinfo.size(); i++)
{
if (i>3)
{
std::cout << vec_stinfo[2] << " =" << vec_stinfo[3] << std::endl;
}
}
}
}


}

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值