How to analyze page elements and handle them accordingly

Source: Internet
Author: User

How to analyze the elements of the Web page, and then do the appropriate processing, such as filling, submitting, etc.

#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 send failure";
}
Pdisp->release ();
tagVARIANT A,i;
A.VT=VT_UI4;
a.lval=0;//This value is the order of the form you want to fill out throughout the page, 0 is the first form
if (Pelement->item (a,i,&pdisp)!=S_OK)
{
Pelement->release ();
Pdisp->release ();
Return "2 send Failure";
}
Pelement->release ();
ihtmlformelement* Pformelem=null;
if (pdisp)
{
if (! Succeeded (Pdisp->queryinterface (Iid_ihtmlformelement, (lpvoid*) &pformelem))
{
Pformelem->release ();
Pdisp->release ();
Return "3 Send Failure";
}
}
Else
{
Return "31 Send Failure";
}
Pdisp->release ();
Lpdispatch pdisp_msg = NULL;
tagVARIANT Phone,msg,empty;
PHONE.VT=VT_UI4;
phone.lval=0;//This value is the order of the input box in the form
MSG.VT=VT_UI4;
msg.lval=1;//This value is the order of the text box in the form
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 send Failure";
}
ihtmlinputtextelement* Phoneelem=null;
ihtmltextareaelement* Msgelem;
if (!pdisp| |! PDISP_MSG)
Return "11 failure";
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 send Failure";
}
Widestring s_phone,s_msg;
S_phone= "888888"
s_msg= "Hello";
Phoneelem->put_value (S_PHONE.C_BSTR ())/fill in
Msgelem->put_value (S_MSG.C_BSTR ())/fill in
Pformelem->submit ()/Submit
Phoneelem->release ();
Msgelem->release ();
Pdisp->release ();
Pdisp_msg->release ();
Pformelem->release ();
Return "Send Success";
}
}
Return "Send Failed";
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.