首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

VC 抓取动态网页内容,但是抓取的内容没有更新,该怎么处理

2014-01-05 
VC 抓取动态网页内容,但是抓取的内容没有更新本帖最后由 xin_yu_xin 于 2014-01-04 17:34:59 编辑我想抓取

VC 抓取动态网页内容,但是抓取的内容没有更新
本帖最后由 xin_yu_xin 于 2014-01-04 17:34:59 编辑 我想抓取一个每分钟更新一次的网页,但是最后发现抓取的内容和网页的更新没有同步,即网页正常更新,但是抓取的内容没有更新:

#include <afxinet.h>

void CGetHttpContentDlg::GetLight(CString *light)
{
CInternetSession session;
CHttpFile *file = NULL; 
CString strURL = "http://116.55.97.227";
//CString strHtml = "";   //存放网页数据
CStringArray strHtml;   //存放网页数据

try
{
file = (CHttpFile*)session.OpenURL(strURL);
}
catch(CInternetException * m_pException)
{

file = NULL;
m_pException->m_dwError;
m_pException->Delete();
session.Close();
//MessageBox(_T("CInternetException"));
return ;
}

CString strLine;

if(file != NULL)
{
while(file->ReadString(strLine) != NULL)
{
strHtml.Add(strLine) ;
}
}
else
{
MessageBox(_T("fail"));
return ;
}
session.Close();
file->Close();
delete file;
file = NULL;

CString strSample=strHtml.GetAt(15);
CStringArray pSubStrings;
ExtractStr(strSample,TEXT(" "),&pSubStrings);
for(int i=0;i<pSubStrings.GetSize();i++)
{
if(pSubStrings.GetAt(i)=="<br>Light:")
{
*light=pSubStrings.GetAt(i+2);
}
}
delete[] strSample;
pSubStrings.RemoveAll();
        strHtml.RemoveAll();

}
[解决办法]
session.OpenURL(strURL);这里改成
session.OpenURL(strURL, INTERNET_FLAG_TRANSFER_ASCII
[解决办法]
INTERNET_FLAG_RELOAD);

试试。即不从缓存处获取数据

热点排行