我做了一个程序,程序里面有了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>