VC读取网页信息原代码
void CMyDlg::OnOK()
{
BOOL m_bDownloadFailed;
CString str;
for(qh=2007051;qh<=2007051;qh++) {
if(qh==2007008) continue;
str.Format("%d",qh);
m_bDownloadFailed=GetSourceHtml ("d://zc_fenzu//"+str+"hmcg.txt",1,1);//下载提示文件的默认网址
m_bDownloadFailed=GetSourceHtml ("d://zc_fenzu//"+str+"hmlc.txt",2,2);//下载提示文件的默认网址
m_bDownloadFailed=GetSourceHtml("d://zc_fenzu//"+str+"hmdg.txt",3,3);//下载提示文件的默认网址
m_bDownloadFailed=GetSourceHtml("d://zc_fenzu//"+str+"2048.txt",4,4);//下载提示文件的默认网址
m_bDownloadFailed=GetSourceHtml("d://zc_fenzu//"+str+"128.txt",5,5);//下载提示文件的默认网址
m_bDownloadFailed=GetSourceHtml("d://zc_fenzu//"+str+"dan.txt",6,6);//下载提示文件的默认网址
m_bDownloadFailed=GetSourceHtml("d://zc_fenzu//"+str+"mtfx.txt",7,7);//下载提示文件的默认网址
}
this->MessageBox("当局开放快速dfkl");
|
bool CMyDlg::GetSourceHtml(CString Filename,int s,int e) { CString str; CInternetSession session; CInternetFile* file = NULL; CStdioFile dataStore;
CString somecode; //也可采用LPTSTR类型,将不会删除文本中的/n回车符 BOOL bIsOk = dataStore.Open(Filename, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite | CFile::typeBinary );
for(int k=s-1;k<e;k++) { try { str.Format("%d",qh); str=str.Right(5); // 试着连接到指定URL if(k<6) //"http://north.500wan.com/n_opencode/media/sfc_06001_media_5.txt file = (CInternetFile*) session.OpenURL(str1+str+a_str[k]); else file = (CInternetFile*) session.OpenURL(str2+str+a_str[k]); } catch (CInternetException* m_pException) { // 如果有错误的话,置文件为空 file = NULL; m_pException->Delete(); return FALSE; } // 用dataStore来保存读取的网页文件
if(file) { while (file->ReadString(somecode) != NULL) //如果采用LPTSTR类型,读取最大个数nMax置0,使它遇空字符时结束 { dataStore.WriteString(somecode); dataStore.WriteString("/n"); //如果somecode采用LPTSTR类型,可不用此句 } file->Close(); delete file; } }
dataStore.Close();
return TRUE; } | |