BOOL SimpleBrowser::GetElementText(LPCTSTR elementName, LPTSTR bf, UINT bfLen) { IHTMLDocument3* pDocument = GetDocument3(); if (pDocument == NULL) return FALSE; BOOL bRet = FALSE; IHTMLElement* pElement = NULL; CComBSTR elemName = elementName; if (pDocument->getElementById(elemName, &pElement) == S_OK && pElement != NULL) { CComBSTR innerText; if (pElement->get_innerText(&innerText) == S_OK) { if (innerText.Length() > 0) { _tcsncpy(bf, innerText, bfLen); bf[bfLen - 1] = 0; } else bf[0] = 0; bRet = TRUE; } pElement->Release(); } pDocument->Release(); return bRet; }
HRESULT CSinaSvr::CheckLoginStatus(CString URL) { if(m_ActionStatus != SINA_LOGINING) return S_FALSE; /* check login pwd //http://login.sina.com.cn/sso/login.php */ long ulen = 0; IHTMLDocument3 *pDoc3 = GetDocument3(); HRESULT hr = E_FAIL; if (URL.Find(_T("http://login.sina.com.cn/sso/login.php"),0) >= 0) { CComBSTR strName = _T("retcode"); CComQIPtr<IHTMLElementCollection> i_Collect; CComQIPtr<IDispatch> i_Dispath; CComQIPtr<IHTMLInputElement> iInput; pDoc3->getElementsByName(strName,&i_Collect); i_Collect->get_length(&ulen); for (long i=0;i<ulen;i++){ i_Dispath = getElementInCollection(i_Collect,i); hr = i_Dispath-> QueryInterface(IID_IHTMLInputElement,(void **)&iInput); CComBSTR str; iInput->get_value(&str); m_ActionStatus = SINA_PWD_ERROR; return S_OK; } } pDoc3->Release(); //http://weibo.com/signup/full_info.php?uid=2452258262&type=2&r=/2452258262 not regist for weibo. if (URL.Find(_T("http://weibo.com/signup/full_info.php?uid="),0) >= 0) { m_ActionStatus = SINA_NO_WEIBO; return S_OK; } CString strHtml; IHTMLDocument2 *pDoc = GetDocument(); GetCookie(pDoc,m_strCookie); GetSource(pDoc,strHtml); pDoc->Release(); FILE *f = _tfopen(_T("cookie.txt"),_T("w")); fwrite(m_strCookie.GetBuffer(),1,m_strCookie.GetLength()*2,f); fclose(f); f = _tfopen(_T("html.txt"),_T("w")); fwrite(strHtml.GetBuffer(),1,strHtml.GetLength(),f); fclose(f); return S_OK; }