<b>若何解析网页元素并举行呼应处理</b>[VC/C++编程]
本文“<b>若何解析网页元素并举行呼应处理</b>[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
若何解析网页元素,然后举行呼应处理,比方填表,递交等等
#include <Mshtml.h>
AnsiString __fastcall TForm3::Submit(void)
{
IHTMLDocument2 *pHTMLDoc = NULL;
LPDISPATCH pDisp = NULL;
pDisp =CppWebBrowser1->Document;
if(pDisp)
{
if (SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pHTMLDoc)))
{
pDisp->Release();
IHTMLElementCollection *pelement;
if(pHTMLDoc->get_forms(&pelement)!=S_OK)
{
pHTMLDoc->Release();
pDisp->Release();
pelement->Release();
return "1发送失利";
}
pDisp->Release();
tagVARIANT a,i;
a.vt=VT_UI4;
a.lVal=0;//这个值为你所要填写的表单在整个网页中的次序,0为第一个表单
if(pelement->item(a,i,&pDisp)!=S_OK)
{
pelement->Release();
pDisp->Release();
return "2发送失利";
}
pelement->Release();
IHTMLFormElement* pFormElem=NULL;
if(pDisp)
{
if(!SUCCEEDED(pDisp->QueryInterface(IID_IHTMLFormElement,(LPVOID*)&pFormElem)))
{
pFormElem->Release();
pDisp->Release();
return "3发送失利";
}
}
else
{
return "31发送失利";
}
pDisp->Release();
LPDISPATCH pDisp_msg = NULL;
tagVARIANT phone,msg,empty;
phone.vt=VT_UI4;
phone.lVal=0;//这个值为Input框在表单中的次序
msg.vt=VT_UI4;
msg.lVal=1;//这个值为Text文本框在表单中的次序
if((pFormElem->item(phone,empty,&pDisp)!=S_OK)||(pFormElem->item(msg,empty,&pDisp_msg)!=S_OK))
{
pFormElem->Release();
if(pDisp)
pDisp->Release();
if(pDisp_msg)
pDisp_msg->Release();
return "4发送失利";
}
IHTMLInputTextElement* phoneElem=NULL;
IHTMLTextAreaElement* msgElem;
if(!pDisp||!pDisp_msg)
return "11失利";
if (!SUCCEEDED(pDisp->QueryInterface(IID_IHTMLInputTextElement, (void**)&phoneElem))||(!SUCCEEDED(pDisp_msg->QueryInterface(IID_IHTMLTextAreaElement, (void**)&msgElem))))
{
if(phoneElem)
phoneElem->Release();
if(msgElem)
msgElem->Release();
if(pDisp)
pDisp->Release();
if(pDisp_msg)
pDisp_msg->Release();
return "5发送失利";
}
WideString s_phone,s_msg;
s_phone="888888"
s_msg="你好";
phoneElem->put_value(s_phone.c_bstr());//填写
msgElem->put_value(s_msg.c_bstr());//填写
pFormElem->submit();//提交
phoneElem->Release();
msgElem->Release();
pDisp->Release();
pDisp_msg->Release();
pFormElem->Release();
return "发送成功";
}
}
return "发送失利";
}
以上是“<b>若何解析网页元素并举行呼应处理</b>[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |