15,471
社区成员
发帖
与我相关
我的任务
分享
bool CEngine::GetSourceHtml( const CString &theUrl, CStringBuf &buf )
{
CInternetFile* file = NULL;
CInternetSession session; //当执行这个一句时,theUrl值竟然被改变了
CString str;
try
{
// 试着连接到指定URL
file = (CInternetFile*) session.OpenURL(theUrl);
}
catch (CInternetException* m_pException)
{
m_pException->Delete();
return false;
}
buf.m_buf="";
while( file->ReadString(str) != NULL )
{
buf.m_buf+=str;
}
buf.m_language = HTML_LAN_CHINESE;
return true;
}
void CEngine::Run(const CString &url, int depth)
{
SetUrlAndDepth(url,depth);
CloseHandle( CreateThread(NULL, 0, Go2, (LPVOID)this, 0, NULL) );
}
DWORD WINAPI CEngine::Go2( LPVOID lpParam )
{
CEngine *g = (CEngine*) lpParam;
g->Go(g->m_url, g->m_depth);
AfxMessageBox(_T("complete"));
return 1;
}
bool CEngine::Go(const CString &url, int depth)
{
CComPtr<IDispatch> spDispatch;
MSHTML::IHTMLDocument2Ptr pDoc;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IHTMLElementCollection> pElementCol;
CComPtr<IHTMLAnchorElement> pLoct;
CStringBuf buf;
MSHTML::IHTMLElementCollectionPtr pCollection;
MSHTML::IHTMLElementPtr pElement;
if( depth <= 0 || !m_hash.Insert((LPCSTR)url) )
return false;
if( !GetSourceHtml(url, buf) )
return false;
pDoc = GetDocument(buf);
...
}