VC++写的某平台网络游戏币交易成交采集器,仅供学习娱乐

某平台网络游戏币交易成交采集器,仅供学习娱乐
工具vc6.0或以上
系统windos xp以上
在这里插入图片描述

代码如下:
1新建一对话框项目,添加两个CListCtrl列表和1个REdit控件,和3个按钮
在这里插入图片描述
添加按钮’手游’响应事件
GetDlgItem(IDC_BTN_CAIJI2)->EnableWindow(FALSE);
AfxBeginThread((AFX_THREADPROC)CaijiThread, this);

下面是采集线程

UINT CaijiThread(CTestDlg* pDlg)
{
//获得游戏列表
//https://sy.dd373.com/MobileGameList.shtml
pDlg->m_pList->DeleteAllItems();
pDlg->m_pList2->DeleteAllItems();
CString sHtml;
GetHttpString(sHtml, “http://api.dd373.com/MobileGame/GetMonileGameList?key=%E5%85%A8%E9%83%A8&GameShort=hot&type=1”);
if(sHtml.GetLength()>0)
{
CString sSec = UTF8ToGB(sHtml.GetBuffer(0));//.Mid(k1, k2-k1);
CStringArray arrList;
GetStringList(sSec, “GameName:’”, arrList);
dbg("%d游戏列表:%d", sHtml.GetLength(), arrList.GetSize());
int nCnt = 0;
CStringArray arrGameID, arrGameName;
for(int i=0;i<arrList.GetSize();i++)
{
CString sCur = arrList.GetAt(i);
if(sCur.Find(“GameIdentify”)-1)continue;
if(sCur.Find(“GameType”)
-1)continue;
//dbg("[%d]%s", nCnt, sCur);
nCnt++;

		int p = sCur.Find("'");
		CString sName = sCur.Left(p);

		CString sGameId;
		char sKey[] = "GameIdentify:'";
		int n1 = strlen(sKey);
		int k1 = sCur.Find(sKey);
		int k2 = sCur.Find("'", k1+n1);
		if(k1>0 && k2>0)
		{
			sGameId = sCur.Mid(k1+n1, k2-k1-n1);
			//dbg("sGameId[%s]", sGameId);
		}else
		{
			dbg("游戏列表关键字查找失败");
		}
		if(sName.GetLength()>0 && sGameId.GetLength()>0)
		{
			pDlg->m_pList->InsertItem(pDlg->m_pList->GetItemCount(), sName);
			pDlg->m_pList->SetItemText(pDlg->m_pList->GetItemCount()-1, 1, sGameId);
			arrGameName.Add(sName);
			arrGameID.Add(sGameId);
		}
	}

	//交易完成http://sy.dd373.com/finishlist/bhbg9s-0-0-0-0-0-0-0-0-0-0-0.html
	CString sURL, sTmp;
	for(i=0;i<arrGameName.GetSize();i++)
	{
		pDlg->m_pList2->InsertItem(pDlg->m_pList2->GetItemCount(), arrGameName.GetAt(i));
		sURL.Format("http://sy.dd373.com/finishlist/%s-0-0-0-0-0-0-0-0-0-0-0.html", arrGameID.GetAt(i));
		GetHttpString(sHtml, sURL.GetBuffer(0));
		dbg("[%d]sURL[%s]%s", sHtml.GetLength(), sURL, arrGameName.GetAt(i));
		if(sHtml.GetLength()>0)
		{
			CStringArray arrCJItem;
			GetStringList(sHtml, "gl_content", arrCJItem);
			int nCnt = 0;
			//dbg("------------%s\r\n", sHtml);
			for(int j=0;j<arrCJItem.GetSize();j++)
			{
				CString sCur = arrCJItem.GetAt(j);
				//dbg("=====%s\r\n", sCur);
				if(sCur.Find("goods_t left")!=-1)
				{
					nCnt++;
				}
			}
			//dbg("成交量:%d", nCnt);
			sTmp.Format("%d", nCnt);
			pDlg->m_pList2->SetItemText(pDlg->m_pList2->GetItemCount()-1, 1, sTmp);
		}else
		{
			dbg("获得成交量失败");
		}
		//Sleep(1000*1);
	}
}else
{
	dbg("游戏列表获得失败");
}
pDlg->GetDlgItem(IDC_BTN_CAIJI2)->EnableWindow(1);
return 0;

}

下面这里是采集 ‘网游’的代码
UINT CaijiThread2(CTestDlg* pDlg)
{
//获得游戏列表
//https://sy.dd373.com/MobileGameList.shtml
pDlg->m_pList->DeleteAllItems();
pDlg->m_pList2->DeleteAllItems();
CString sHtml;
GetHttpString(sHtml, “http://api.dd373.com/Game/GetGameByKeyword?keyword=%E5%85%8D%E8%B4%B9%E6%B8%B8%E6%88%8F”);
if(sHtml.GetLength()>0)
{
CString sSec = UTF8ToGB(sHtml.GetBuffer(0));//.Mid(k1, k2-k1);
CStringArray arrList;
GetStringList(sSec, "GameName:’", arrList);
dbg("%d游戏列表:%d", sHtml.GetLength(), arrList.GetSize());
int nCnt = 0;
CStringArray arrGameID, arrGameName;
for(int i=0;i<arrList.GetSize();i++)
{
CString sCur = arrList.GetAt(i);
if(sCur.Find(“GameIdentify”)-1)continue;
dbg("[%d]%s", nCnt, sCur);
//if(sCur.Find(“GameType”)
-1)continue;
nCnt++;

		int p = sCur.Find("'");
		CString sName = sCur.Left(p);

		CString sGameId;
		char sKey[] = "GameIdentify:'";
		int n1 = strlen(sKey);
		int k1 = sCur.Find(sKey);
		int k2 = sCur.Find("'", k1+n1);
		if(k1>0 && k2>0)
		{
			sGameId = sCur.Mid(k1+n1, k2-k1-n1);
			//dbg("sGameId[%s]", sGameId);
		}else
		{
			dbg("游戏列表关键字查找失败");
		}
		if(sName.GetLength()>0 && sGameId.GetLength()>0)
		{
			pDlg->m_pList->InsertItem(pDlg->m_pList->GetItemCount(), sName);
			pDlg->m_pList->SetItemText(pDlg->m_pList->GetItemCount()-1, 1, sGameId);
			arrGameName.Add(sName);
			arrGameID.Add(sGameId);
		}
	}

	//交易完成http://sy.dd373.com/finishlist/bhbg9s-0-0-0-0-0-0-0-0-0-0-0.html
	CString sURL, sTmp;
	for(i=0;i<arrGameName.GetSize();i++)
	{
		pDlg->m_pList2->InsertItem(pDlg->m_pList2->GetItemCount(), arrGameName.GetAt(i));
		//http://www.dd373.com/finishlist/c8rcrf-0-0-0-0-hf9fx0-0-0-0-0-0-0-0-0-0.html
		//http://www.dd373.com/finishlist/nqbax0-0-0-0-0-4jm27f-0-0-0-0-0-0-0-0-0.html
		sURL.Format("http://www.dd373.com/finishlist/%s-0-0-0-0-0-0-0-0-0-0-0-0-0-0.html", arrGameID.GetAt(i));
		GetHttpString(sHtml, sURL.GetBuffer(0));
		dbg("[%d]sURL[%s]%s", sHtml.GetLength(), sURL, arrGameName.GetAt(i));
		if(sHtml.GetLength()>0)
		{
			CStringArray arrCJItem;
			GetStringList(sHtml, "box money_ner", arrCJItem);
			int nCnt = 0;
			//dbg("------------%s\r\n", sHtml);
			for(int j=0;j<arrCJItem.GetSize();j++)
			{
				CString sCur = arrCJItem.GetAt(j);
				//dbg("=====%s\r\n", sCur);
				if(sCur.Find("left title title_normal")!=-1)
				{
					nCnt++;
				}
			}
			//dbg("成交量:%d", nCnt);
			sTmp.Format("%d", nCnt);
			pDlg->m_pList2->SetItemText(pDlg->m_pList2->GetItemCount()-1, 1, sTmp);
		}else
		{
			dbg("获得成交量失败");
		}
		Sleep(1000*3);
	}
}else
{
	dbg("游戏列表获得失败");
}
pDlg->GetDlgItem(IDC_BTN_CAIJI)->EnableWindow(1);
return 0;

}

这里是获得网页源代码函数
#include “AFXINET.H”
void GetHttpString(CString& strHtml, char *m_szURL)
{
CString sTmpURL=m_szURL;
strHtml.Empty();
try
{
CInternetSession sess;//建立会话
DWORD dwFlag = INTERNET_FLAG_TRANSFER_ASCII|INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_RELOAD;

	CHttpFile* pF=(CHttpFile*)sess.OpenURL(m_szURL, 1, dwFlag);//打开文件
	CString szData;
	while(pF->ReadString(szData))
	{//读取文件
		strHtml+="\r\n";
		strHtml+=szData;
	}
	pF->Close();
	sess.Close();
	delete pF;
}
catch(...)///捕捉异常
{
	 dbg("@@@@@@@@@@ CDBAccess::GetHttpString:%s @@@@@@@@@@");
}

}

OK,出结果了,哈哈

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值