我想获取web中form里边的submit按钮信息

shellfish567 2011-09-01 02:17:37
代码如下:
for (long i=0;i<form_num;i++)//遍历每一个表单
{

V_VT(&id) = VT_I4;
V_I4(&id) = i;
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
if (pElementCol->item(id,index,&spDispatch)==S_OK)
{
if (spDispatch->QueryInterface(IID_IHTMLFormElement,(void**)&pFormElement)==S_OK)//获取FORMELEMENT
{
CComBSTR form_name;
char ch_form[100];
memset(ch_form,0,100);
pFormElement->get_name(&form_name);
CComBSTR_to_char(form_name,ch_form,100);
memset(echo_data,0,1024);
sprintf(echo_data,"第%d个表单名为:%s\n",i,ch_form);
this->ui.textEdit->insertPlainText(echo_data);


long item_num=0;
if(pFormElement->get_length(&item_num)==S_OK)
{
for(long j=0;j<item_num;j++)
{
V_VT(&id) = VT_I4;
V_I4(&id) = j;
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
if(pFormElement->item(id,index, &spDispatch)==S_OK)
{
if(spDispatch->QueryInterface(IID_IHTMLInputTextElement,(void**)&pInputElement)==S_OK)
{
CComBSTR value;
CComBSTR name;
CComBSTR type;
CComBSTR cls_ID;
pInputElement->get_type(&type);
if(type==CComBSTR("text"))
{
pInputElement->get_name(&name);
pInputElement->get_value(&value);
memset(echo_data,0,1024);
sprintf(echo_data,"输入框name:");
CComBSTR_to_char(name,echo_data+strlen(echo_data),1024);
sprintf(echo_data+strlen(echo_data),"输入框内的值:");
CComBSTR_to_char(value,echo_data+strlen(echo_data),1024);
strcat(echo_data,"\n");
this->ui.textEdit->insertPlainText(echo_data);
}
else if(type==CComBSTR("password"))
{
pInputElement->get_name(&name);
pInputElement->get_value(&value);
memset(echo_data,0,1024);
sprintf(echo_data,"密码框name:");
CComBSTR_to_char(name,echo_data+strlen(echo_data),1024);
sprintf(echo_data+strlen(echo_data),"密码框内的值:");
CComBSTR_to_char(value,echo_data+strlen(echo_data),1024);
strcat(echo_data,"\n");
this->ui.textEdit->insertPlainText(echo_data);

}

}
else if(spDispatch->QueryInterface(IID_IHTMLElement,(void**)&pElement)==S_OK)
{
CComBSTR value;
CComBSTR name;
CComBSTR type;
CComBSTR cls_ID;
pElement->get_type(&type);
if(type==CComBSTR("submit"))
{
pButtonElement->get_name(&name);
pButtonElement->get_value(&value);
memset(echo_data,0,1024);
sprintf(echo_data,"提交按钮name:");
CComBSTR_to_char(name,echo_data+strlen(echo_data),1024);
sprintf(echo_data+strlen(echo_data),"提交按钮内的值:");
CComBSTR_to_char(value,echo_data+strlen(echo_data),1024);
strcat(echo_data,"\n");
this->ui.textEdit->insertPlainText(echo_data);
}
}
}
}
}

...全文
153 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
shellfish567 2011-09-01
  • 打赏
  • 举报
回复
自己解决了,是IID_IHTMLInputButtonElement。
shellfish567 2011-09-01
  • 打赏
  • 举报
回复
问题如下: if(spDispatch->QueryInterface(IID_IHTMLInputTextElement,(void**)&pInputElement)==S_OK)当我这样获取元素的时候只能获取到输入框类型的元素,当我
else if(spDispatch->QueryInterface(IID_IHTMLElement,(void**)&pElement)==S_OK)这样获取的时候可以获取到所有元素,但是无法调用get_type,也没办法知道到底是不是submit按钮,查MSDN中IID_IHTMLButtonElement是最像的,可是根本获取不到submit,我就是想获取submit按钮,有什么办法?

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧