如何用代码实现点击网页上的某一个按钮

dahaiI0 2011-06-13 08:07:55
CSDN发个图真麻烦。。有几个问题想请教大家
1:网页上有一个EDIT编辑框,如何把一个字符串赋值给它,用findwindow么?但不太会用SPY。。囧
2:如何用代码实现点击网页上的一个按钮。
其实是这样滴,我想做一个批量注册账号的程序,除了用户名和验证码,其他都可以一样,我只需要在自己的对话框中添加一个EDIT用来输入验证码,一个按钮用来完成注册。求帮忙。。谢谢
...全文
812 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
fhljys 2013-11-21
  • 打赏
  • 举报
回复
引用 11 楼 dahaiI0 的回复:
已解决,有时最终还得靠自己啊。验证了一句话,人都是逼出来的啊。。虽然也有剖腹产。
怎么解决的?求详情~
冰凝 2011-06-16
  • 打赏
  • 举报
回复
11楼,,,这。。。额。。。
dahaiI0 2011-06-16
  • 打赏
  • 举报
回复
已解决,有时最终还得靠自己啊。验证了一句话,人都是逼出来的啊。。虽然也有剖腹产。
秋落叶博客 2011-06-15
  • 打赏
  • 举报
回复
都是高手啊
dahaiI0 2011-06-14
  • 打赏
  • 举报
回复
我参考了这份代码,没细看,大多数编辑框能填充内容,但如果是输入密码的编辑框就无效了。

#import <mshtml.tlb> // Internet Explorer 5
#import <shdocvw.dll>
#include "Shlwapi.h "
#pragma comment(lib, "Shlwapi.lib ")
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
SHDocVw::IShellWindowsPtr m_spSHWinds;
if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK)
{
IDispatchPtr spDisp;
long nCount = m_spSHWinds-> GetCount();
for (long i = 0; i < nCount; i++)
{
_variant_t va(i, VT_I4);
spDisp = m_spSHWinds-> Item(va);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL)
{
IDispatchPtr spDisp;
if(spBrowser-> get_Document(&spDisp) == S_OK && spDisp!= 0 )
{
MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp);
MSHTML::IHTMLElementPtr spHtmlElement;
if(spHtmlDocument==NULL)
continue;
spHtmlDocument-> get_body(&spHtmlElement);
if(spHtmlDocument==NULL)
continue;
HRESULT hr;
MSHTML::IHTMLElementCollection* pColl=NULL;
hr=spHtmlDocument-> get_all(&pColl);
if(pColl!=NULL&&SUCCEEDED(hr))
{
long lcount = 0;
pColl-> get_length(&lcount);
for(int i=0;i <lcount;i++)
{
_variant_t index;
index.vt=VT_I4;
index.intVal=i;
IDispatchPtr disp;
disp=pColl-> item(index,index);
if(disp==NULL)
hr=E_FAIL;
else
{
MSHTML::IHTMLInputElementPtr pInput(disp);
if(pInput)
{
BSTR bstrtype;
pInput-> get_type(&bstrtype);
printf(_bstr_t(bstrtype));
if(StrCmpW(bstrtype,L "text ")==0)
{
pInput-> put_value(_bstr_t( "fill it "));
printf( "fill a field\n ");
}
SysFreeString(bstrtype);
}
}


有谁可以给分完整的代码,能给指定编辑框填充字符串,并用代码实现IE上按钮点击,100分送上
dahaiI0 2011-06-14
  • 打赏
  • 举报
回复
3连插·····
skyxie 2011-06-14
  • 打赏
  • 举报
回复
你这个代码只对文本类型的input进行填充,当然就不会填写密码了~
if(StrCmpW(bstrtype,L "text ")==0)
{

密码的input,类型为"password"
dahaiI0 2011-06-14
  • 打赏
  • 举报
回复
谁能给份完整的DEMO。。200分送上。时间紧迫,自己短时间内怕折腾不出来。
dahaiI0 2011-06-14
  • 打赏
  • 举报
回复
多谢6楼。。
dahaiI0 2011-06-13
  • 打赏
  • 举报
回复
3楼能否给的demo,邮箱dahaiI0@163.com
xiaohuh421 2011-06-13
  • 打赏
  • 举报
回复
void COpnPageDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
if(m_pHtmlView)
{
IHTMLDocument2 *pIHTMLDoc=(IHTMLDocument2*)m_pHtmlView->GetHtmlDocument();
if(pIHTMLDoc)
{
EnumFrame(pIHTMLDoc);
CString Str;
CComQIPtr< IHTMLElementCollection > spAllElementCollection;
HRESULT hr = pIHTMLDoc->get_all( &spAllElementCollection ); //
long nAllCount=0;
hr=spAllElementCollection->get_length(&nAllCount);
Str.Format(TEXT("all: %d"),nAllCount);
OutputDebugString(Str);
for(long i = 0 ; i < nAllCount ; i++)
{
IDispatch *pDisp = NULL; //取得第 i 个Link
spAllElementCollection->item( CComVariant(i) , CComVariant() , &pDisp);
if ( pDisp == NULL ) continue;

CComQIPtr< IHTMLElement > spElement = pDisp;
pDisp->Release();
if(!spElement) continue;
CComBSTR bstrSrc;
spElement->get_tagName(&bstrSrc);
CString tStr;
tStr+=bstrSrc.m_str;
tStr+=" ";
/*spElement->get_outerText(&bstrSrc);
tStr+=bstrSrc.m_str;
tStr+=" ";*/

if(_tcsicmp(bstrSrc.m_str,TEXT("A"))==0 || _tcsicmp(bstrSrc.m_str,TEXT("LINK"))==0)
{
spElement->get_outerText(&bstrSrc);
tStr+=bstrSrc.m_str;
tStr+=" ";
/*if(_tcsstr(bstrSrc.m_str,TEXT("同意以下协议"))!=NULL)
{
spElement->click();//这里就是按钮提交
}*/
OutputDebugString(tStr);
}

}
}
}
}

HRESULT COpnPageDlg::EnumFrame(IHTMLDocument2 *pHtmlDoc)
{
if(pHtmlDoc==NULL)
{
return -1;
}
CComPtr< IHTMLFramesCollection2 > spFramesCollection2;
pHtmlDoc->get_frames( &spFramesCollection2 ); //取得框架frame的集合
long nFrameCount=0; //取得子框架个数
HRESULT hr = spFramesCollection2->get_length( &nFrameCount );
if(hr>=0 && nFrameCount>0)
{
CString Str;
Str.Format(TEXT("frames:%d"),nFrameCount);
OutputDebugString(Str);
for(int i=0;i<nFrameCount;i++)
{
CComVariant vDispWin2; //取得子框架的自动化接口
hr=spFramesCollection2->item(&CComVariant(i) , &vDispWin2);

//取得子框架的 IHTMLWindow2 接口
CComQIPtr< IHTMLWindow2 > spWin2 = vDispWin2.pdispVal;
if( !spWin2 ) continue;

CComPtr < IHTMLDocument2 > spDoc2;
spWin2->get_document( &spDoc2 ); //取得子框架的 IHTMLDocument2 接口
EnumFrame(spDoc2);


CComQIPtr< IHTMLElementCollection > spAllElementCollection;
hr = pHtmlDoc->get_links( &spAllElementCollection ); //
long nAllCount=0;
hr=spAllElementCollection->get_length(&nAllCount);
Str.Format(TEXT("all: %d"),nAllCount);
OutputDebugString(Str);
for(long i = 0 ; i < nAllCount ; i++)
{
IDispatch *pDisp = NULL; //取得第 i 个Link
spAllElementCollection->item( CComVariant(i) , CComVariant() , &pDisp);
if ( pDisp == NULL ) continue;

CComQIPtr< IHTMLElement > spElement = pDisp;
pDisp->Release();
if(!spElement) continue;
CComBSTR bstrSrc;
spElement->get_tagName(&bstrSrc);
CString tStr;
tStr+=bstrSrc.m_str;
tStr+=" ";
if(_tcsicmp(bstrSrc.m_str,TEXT("A"))==0 || _tcsicmp(bstrSrc.m_str,TEXT("LINK"))==0 )
{
spElement->get_outerText(&bstrSrc);
tStr+=bstrSrc.m_str;
tStr+=" ";
}
OutputDebugString(tStr);

}
}
}
return hr;
}
dahaiI0 2011-06-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 simoreg 的回复:]
网页上很少用Windows控件 ,你不要打算这样搞,行不通的
[/Quote]
以前没玩过这个,仅凭自己微弱的知识想的。能否指教下。时间有点点紧所以没怎么用心查资料
simoreg 2011-06-13
  • 打赏
  • 举报
回复
网页上很少用Windows控件 ,你不要打算这样搞,行不通的

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧