描述:
偶学习人家的代码如下,想修改自动登陆上chinahr刷新简历
请教各位高手:
1。为什么提交表格不能成功登陆
2、如何模拟在网页中按下按钮
void CYahooDlg::OnBnClickedButton1()
{
BSTR bsStatus;
bReady=0;
CString mPass("Password"); //<-------- Your Password here
CString mUser("user");//<-------- Your user ID here
BSTR bsPW = mPass.AllocSysString();
BSTR bsUser=mUser.AllocSysString();
CString mStr;
HRESULT hr1 ;
hr1 = CoInitialize(NULL);
if(!SUCCEEDED(hr1))
return ;
hr1 = CoCreateInstance (CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER,
IID_IWebBrowser2, (LPVOID *)&pBrowser); //Create an Instance of web browser
if(hr1==S_OK)
{
VARIANT_BOOL pBool=true;
pBrowser->put_Visible( pBool ) ; //Commentout this line if you dont want the browser to be displayed
COleVariant vaURL("http://my.chinahr.com/login.aspx") ; //the yahoo mail site
COleVariant null;
pBrowser->Navigate2(vaURL,null,null,null,null) ; //Open the mail login page
while(!bReady) //This while loop maks sure that the page is fully loaded before we go to the next page
{
pBrowser->get_StatusText(&bsStatus);
mStr=bsStatus;
if(mStr=="完毕")bReady=1;
}
IDispatch* pDisp;
hr1=pBrowser->get_Document(&pDisp);//Get the underlying document object of the browser
if (pDisp != NULL )
{
IHTMLDocument2* pHTMLDocument2;
HRESULT hr;
hr = pDisp->QueryInterface( IID_IHTMLDocument2,
(void**)&pHTMLDocument2 );//Ask for an HTMLDocument2 interface
if (hr == S_OK)
{
IHTMLElementCollection* pColl = NULL;//Enumerate the HTML elements
hr = pHTMLDocument2->get_all( &pColl );
if (hr == S_OK && pColl != NULL)
{
LONG celem;
hr = pColl->get_length( &celem );//Find the count of the elements
if ( hr == S_OK )
{
for ( int i=0; i< celem; i++ )//Loop through each elment
{
VARIANT varIndex;
varIndex.vt = VT_UINT;
varIndex.lVal = i;
VARIANT var2;
VariantInit( &var2 );
IDispatch* pDisp;
hr = pColl->item( varIndex, var2, &pDisp );//Get an element
if ( hr == S_OK )
{
IHTMLElement* pElem;
hr = pDisp->QueryInterface( //Ask for an HTMLElemnt interface
IID_IHTMLElement,
(void **)&pElem);
if ( hr == S_OK )
{
BSTR bstr;
hr = pElem->get_tagName(&bstr);//Get the tag name for the element
CString strTag;
strTag = bstr;
IHTMLInputTextElement* pUser;//We need to check for input elemnt on login screen
hr = pDisp->QueryInterface(
&nbs