用c++Builder 怎么获取html内容
1个回答
2017-06-22 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
CppWebBrowser的使用三 获取表单内容
主要函数如下:
AnsiString __fastcall TMainForm::GetFormValue(TCppWebBrowser *CppWebBrowser1, AnsiString ActionStr)
{
//赋值
AnsiString MyStr = ActionStr;
AnsiString SName,SId,SValue;
AnsiString ReturnStr; //返回值
ReturnStr = "";
SName = MyStr.SubString(1,MyStr.Pos(",")-1);
MyStr = MyStr.SubString(MyStr.Pos(",") 1,MyStr.Length()-MyStr.Pos(","));
SId = MyStr.SubString(1,MyStr.Pos(",")-1);
SValue = MyStr.SubString(MyStr.Pos(",") 1,MyStr.Length());
if(SValue==NULL)SValue="";
VARIANT id, index,id1,index1;
IDispatch *spDispatch;
IHTMLDocument2 *pDoc2;
IHTMLElement *pElement;
IHTMLElementCollection *pElementCol;
IHTMLFormElement *pFormElement;
IHTMLInputElement *pInputElement;//Input
IHTMLTextAreaElement* pTextAreaElement;// TextArea
IDispatch *WebDocument=static_cast<IDispatch*>(CppWebBrowser1->Document);
pDoc2=static_cast<IHTMLDocument2*>(WebDocument);
//首先获取IWebBrowser2接口
if (SUCCEEDED(pDoc2->get_forms(&pElementCol))) //得到form
{
long p=0;
if(SUCCEEDED(pElementCol->get_length(&p))) //哪一个form
if(p!=0)
{
for(long i=0;i<=(p-1);i )
{
V_VT(&id) = VT_I4;
V_I4(&id) = i;
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
if(SUCCEEDED(pElementCol->item(id,index, &spDispatch)))
{
if(SUCCEEDED(spDispatch->QueryInterface(IID_IHTMLFormElement,(void**)&pFormElement)))
{
long q=0;
if(SUCCEEDED(pFormElement->get_length(&q))) //得到form中的控件个数
for(long j=0;j<=(q-1);j )
{
V_VT(&id) = VT_I4;
V_I4(&id) = j;
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
if(SUCCEEDED(pFormElement->item(id,index, &spDispatch)))
{
if(SUCCEEDED(spDispatch->QueryInterface(IID_IHTMLElement,(void**)&pElement)))
主要函数如下:
AnsiString __fastcall TMainForm::GetFormValue(TCppWebBrowser *CppWebBrowser1, AnsiString ActionStr)
{
//赋值
AnsiString MyStr = ActionStr;
AnsiString SName,SId,SValue;
AnsiString ReturnStr; //返回值
ReturnStr = "";
SName = MyStr.SubString(1,MyStr.Pos(",")-1);
MyStr = MyStr.SubString(MyStr.Pos(",") 1,MyStr.Length()-MyStr.Pos(","));
SId = MyStr.SubString(1,MyStr.Pos(",")-1);
SValue = MyStr.SubString(MyStr.Pos(",") 1,MyStr.Length());
if(SValue==NULL)SValue="";
VARIANT id, index,id1,index1;
IDispatch *spDispatch;
IHTMLDocument2 *pDoc2;
IHTMLElement *pElement;
IHTMLElementCollection *pElementCol;
IHTMLFormElement *pFormElement;
IHTMLInputElement *pInputElement;//Input
IHTMLTextAreaElement* pTextAreaElement;// TextArea
IDispatch *WebDocument=static_cast<IDispatch*>(CppWebBrowser1->Document);
pDoc2=static_cast<IHTMLDocument2*>(WebDocument);
//首先获取IWebBrowser2接口
if (SUCCEEDED(pDoc2->get_forms(&pElementCol))) //得到form
{
long p=0;
if(SUCCEEDED(pElementCol->get_length(&p))) //哪一个form
if(p!=0)
{
for(long i=0;i<=(p-1);i )
{
V_VT(&id) = VT_I4;
V_I4(&id) = i;
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
if(SUCCEEDED(pElementCol->item(id,index, &spDispatch)))
{
if(SUCCEEDED(spDispatch->QueryInterface(IID_IHTMLFormElement,(void**)&pFormElement)))
{
long q=0;
if(SUCCEEDED(pFormElement->get_length(&q))) //得到form中的控件个数
for(long j=0;j<=(q-1);j )
{
V_VT(&id) = VT_I4;
V_I4(&id) = j;
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
if(SUCCEEDED(pFormElement->item(id,index, &spDispatch)))
{
if(SUCCEEDED(spDispatch->QueryInterface(IID_IHTMLElement,(void**)&pElement)))
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询