我做了一个程序,程序里面有了Web浏览器控件,我用CComQIPtr实现了表单的自动填写,和自动提交,但是有的网页中的submit有name,有的却没有,如果没有的话我就不知道怎么实现自动提交了,刚开始做这方面的程序感觉比较棘手。
比如网页中有name的submit:
<form name="f" action="/s"><span class="s_ipt_wr"><input type="text" name="wd" id="kw" maxlength="100" class="s_ipt">
这样我就可以利用CComQIPtr来进行自动提交表单
///////////////////实现代码/////////////////////////////////////////////
CComPtr < IDispatch > spDispDoc;
spDispDoc = m_web.get_Document();
CComQIPtr< IHTMLDocument2 > spDocument2 = spDispDoc;
CComQIPtr< IHTMLElementCollection > spElementCollection;
if(SUCCEEDED(spDocument2->get_all(&spElementCollection)))
{
CComPtr<IDispatch> spDisp;
HRESULT hr;
hr = spElementCollection->item(CComVariant("form"), CComVariant("0"), &spDisp);//找到提交按钮
if(SUCCEEDED(hr))
{ CComQIPtr<IHTMLFormElement> spForm = spDisp;
spForm->submit();
}
}
这样我就实现了自动提交表单,但是有的网页中只有button或者只有submit的,没有name我不知道如何来实现自动提交表单:
1.这种只有个submit没有name,我无法通过程序来自动提交表单:
<input class="" type="submit" value="立即注册" title="立即注册" tabindex="21" id="submit"/>
2.这种只有个button没有name,我也无法通过程序来自动提交表单:
<button type="submit" class="pn vm" tabindex="904" style="width: 75px;"><em>登录</em></button></td>
比如网页中有name的submit:
<form name="f" action="/s"><span class="s_ipt_wr"><input type="text" name="wd" id="kw" maxlength="100" class="s_ipt">
这样我就可以利用CComQIPtr来进行自动提交表单
///////////////////实现代码/////////////////////////////////////////////
CComPtr < IDispatch > spDispDoc;
spDispDoc = m_web.get_Document();
CComQIPtr< IHTMLDocument2 > spDocument2 = spDispDoc;
CComQIPtr< IHTMLElementCollection > spElementCollection;
if(SUCCEEDED(spDocument2->get_all(&spElementCollection)))
{
CComPtr<IDispatch> spDisp;
HRESULT hr;
hr = spElementCollection->item(CComVariant("form"), CComVariant("0"), &spDisp);//找到提交按钮
if(SUCCEEDED(hr))
{ CComQIPtr<IHTMLFormElement> spForm = spDisp;
spForm->submit();
}
}
这样我就实现了自动提交表单,但是有的网页中只有button或者只有submit的,没有name我不知道如何来实现自动提交表单:
1.这种只有个submit没有name,我无法通过程序来自动提交表单:
<input class="" type="submit" value="立即注册" title="立即注册" tabindex="21" id="submit"/>
2.这种只有个button没有name,我也无法通过程序来自动提交表单:
<button type="submit" class="pn vm" tabindex="904" style="width: 75px;"><em>登录</em></button></td>
解决方案 »
- vc6.0 怎么做activeX安全控件
- ATL编写COM组件时,如何为组件接口中的方法的参数设定缺省值?
- IOleWindow::GetWindow 0x8001010D: 因为应用程序正在发送一个输入同步呼叫,所以无法执行传出的呼叫。
- 100分!如何获取窗口控制框(如关闭按钮最大化按钮)的句柄?
- 请教**有关接口参数问题**
- 怎样将用户在客户区用鼠标绘制的图保存为位图形式?
- 如何理解链表??
- 如何编程实现改变系统的DNS和网关?
- 颜色表和调色表的联系和区别!!
- 请教应该如何处理,First-chance exception : Microsoft C++ Exception?
- BEGIN_EVENTSINK_MAP(CFixedHtmlView, CFormView)消息机制
- 关于进程中出现未知线程的问题
也可以遍历对象, get_tagName, get_type, get_innerText... 来判断对象是否是你需要的