| 关键词: nbsp dataStore 文件 file CFile somecode CString 网页 GetSourceHtml CInternetFile |
基本构成思想: 利用WinInet类,直接打开会话,进行读取并保存网页来相关文件中。本文提供的GetSourceHtml函数封装了该功能,只要提供网址与保存文件名就可以完成全部操作,具体函数如下: BOOL GetSourceHtml(CString theUrl,CString Filename) { CInternetSession session; CInternetFile* file = NULL; try { // 试着连接到指定URL file = (CInternetFile*) session.OpenURL(theUrl); } catch (CInternetException* m_pException) { // 如果有错误的话,置文件为空 file = NULL; m_pException->Delete(); return FALSE; } // 用dataStore来保存读取的网页文件 CStdioFile dataStore; if (file) { CString somecode; //也可采用LPTSTR类型,将不会删除文本中的 回车符 BOOL bIsOk = dataStore.Open(strPath+"\\"+Filename, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite | CFile::typeText); if (!bIsOk) return FALSE; // 读写网页文件,直到为空 while (file->ReadString(somecode) != NULL) //如果采用LPTSTR类型,读取最大个数nMax置0,使它遇空字符时结束 { dataStore.WriteString(somecode); |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|