【求救啊】没有form,没有name,只有id和无数个tr和td,怎么找控件?

jonnyhe 2015-08-12 08:04:25
准备用BCB6 的CppWebBroswer搞页面遍历,现在卡在登录这个事情上了。。
在网上找了好几个实例,都是说用IHTMLInputElement这个方法,来遍历查找控件name,id啥的,
关键是,我现在这边的web上面,只有一个input输入框和一个按钮,还都没有name,也没有用form,
已有的示例试了下都不行,

贴一下网页的源码:
<body data-spy="scroll" data-target=".bs-docs-sidebar" style="background-color:#e7e7e7;" class="ember-application">
<div id="indexcontent" class="clearboth" align="center" style="height:612px;">
<img id="guidebg" src="/res/bg.jpg" height="642px" style="right:0;bottom:0;position:absolute;top:0;left:0;z-index:-1;width:100%;min-width:1000px;">
<div class="clearboth rounddiv" style="width:1000px;padding-top:42px;">
<div align="center" class="clearboth width_100p">
<div class="clearboth">
<table style="width:626px;height:440px;margin-left:3px;" cellpadding="0" cellspacing="0" frame="void" rules="none">
<tbody>
<tr>
<td style="text-align:center;width:100%;">
<div id="logintable" align="center" style="color:#ffffff;margin-top:27px;margin-left:4px;">
<div id="ember273" class="ember-view">
<table id="ember311" class="ember-view">
<tbody><tr><td id="logininfo" style="height:40px;font-size:14px;color:#e0ecf7;text-align:left;padding-left:5px;"><script id="metamorph-4-start" type="text/x-placeholder"></script>请输入登录密码<script id="metamorph-4-end" type="text/x-placeholder"></script></td></tr>
<tr><td id="loginpassword" style="padding-left:2px;">
<div class="input_left"> </div>
<input autocomplete="off" type="password" class="input_text" id="userpassword" onkeydown="fncKeyStop(event);" onpaste="return false;" oncontextmenu="return false;" style="width:293px;color:#ffffff;">
<div class="input_right"> </div>
</td></tr>
<tr><td id="loginerror" style="height:20px;"><table id="loginerrortable" class="hide" style="display: table;"><tbody><tr><td><div class="ic-sign"></div></td><td style="padding-left:5px;color:#b7d4ec;font-size:12px;" id="errorCategory">密码有误,请重新输入。</td></tr></tbody></table></td></tr>
<tr><td style="height:80px;">
<div id="ember316" class="ember-view">
<button id="loginbtn" class="loginbutton" style="font-size:18px;color:white;" onclick="Atp.LoginController.postData();"><script id="metamorph-5-start" type="text/x-placeholder"></script>登录<script id="metamorph-5-end" type="text/x-placeholder"></script></button>
</div>
</td></tr>
</tbody></table>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>

有没有大神帮忙看下,怎么用下面这套东东实现自动填表登录啊~
IDispatch *spDispatch;
IHTMLDocument2 *pDoc2;
IHTMLElement *pElement;
IHTMLElementCollection *pElementCol;
IHTMLFormElement *pFormElement;
IHTMLInputElement *pInputElement;

...全文
566 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jonnyhe 2015-08-19
  • 打赏
  • 举报
回复
引用 8 楼 ksrsoft 的回复:
是有ID的 分别是 userpassword loginbtn 这个东西我感觉用delphi方便写,所以是delphi语法 头文件MSHTML

procedure TFrmLogin.Button1Click(Sender: TObject);
var
  doc2: IHTMLDocument2;
  doc3: IHTMLDocument3;
  ec: IHTMLElementCollection;
  elmt: IHTMLElement;
  i, j, k: Integer;
  str: string;
begin

  doc2 := Self.WebBrowser1.Document as IHTMLDocument2;
  doc3 := Self.WebBrowser1.Document as IHTMLDocument3;

  elmt := doc3.getElementById('userpassword');
  elmt.id;
  elmt._className;
  elmt.tagName;
  elmt.setAttribute('value', 'abcdef4564564564', 0);

  elmt := doc3.getElementById('loginbtn');
  elmt.click;

end;

procedure TFrmLogin.FormCreate(Sender: TObject);
begin
  Self.WebBrowser1.Navigate('E:\TestCode\DE8\ParseHTML\login.html');
end;
感谢大神!我试着改成 BCB,可是有些问题不会解,能不能帮忙指导下? IDispatch *spDispatch; IHTMLDocument2 *doc2 ; IHTMLDocument3 *doc3; IHTMLElementCollection *ec; IHTMLElement *elmt; int i,j,k; IDispatch *WebDocument=static_cast <IDispatch*> (cWeb->Document); doc2=static_cast <IHTMLDocument2*> (WebDocument); doc3=static_cast <IHTMLDocument3*> (WebDocument); WideString wPwdid = "userpassword"; WideString wPwdAttr = "value"; doc3->getElementById(wPwdid.c_bstr(),(IHTMLElement **)elmt); elmt->setAttribute(wPwdAttr.c_bstr(),/*这里需要tagVARIANT类型的值,不知道咋传进去...*/,0);
缘中人 2015-08-14
  • 打赏
  • 举报
回复
参考这个 http://blog.csdn.net/baronyang/article/details/7485258 功能很强大
缘中人 2015-08-14
  • 打赏
  • 举报
回复
是有ID的 分别是 userpassword loginbtn 这个东西我感觉用delphi方便写,所以是delphi语法 头文件MSHTML

procedure TFrmLogin.Button1Click(Sender: TObject);
var
  doc2: IHTMLDocument2;
  doc3: IHTMLDocument3;
  ec: IHTMLElementCollection;
  elmt: IHTMLElement;
  i, j, k: Integer;
  str: string;
begin

  doc2 := Self.WebBrowser1.Document as IHTMLDocument2;
  doc3 := Self.WebBrowser1.Document as IHTMLDocument3;

  elmt := doc3.getElementById('userpassword');
  elmt.id;
  elmt._className;
  elmt.tagName;
  elmt.setAttribute('value', 'abcdef4564564564', 0);

  elmt := doc3.getElementById('loginbtn');
  elmt.click;

end;

procedure TFrmLogin.FormCreate(Sender: TObject);
begin
  Self.WebBrowser1.Navigate('E:\TestCode\DE8\ParseHTML\login.html');
end;
缘中人 2015-08-13
  • 打赏
  • 举报
回复
明天解析试试
缘中人 2015-08-13
  • 打赏
  • 举报
回复
url是内网,没有外网的url吗
jonnyhe 2015-08-13
  • 打赏
  • 举报
回复
引用 3 楼 ksrsoft 的回复:
想模拟登陆吗 有url吗
有URL,是http://192.168.3.1/html/index.html 登录以后的URL是 http://192.168.3.1/html/content.html
缘中人 2015-08-13
  • 打赏
  • 举报
回复
想模拟登陆吗 有url吗
jonnyhe 2015-08-13
  • 打赏
  • 举报
回复
引用 5 楼 ksrsoft 的回复:
url是内网,没有外网的url吗
没有外网可以打开的URL地址,要看显示的话,可以把最上面的网页源码复制到txt,保存成html格式文件,本地用IE打开就可以了。
jonnyhe 2015-08-12
  • 打赏
  • 举报
回复
<input autocomplete="off" type="password" class="input_text" id="userpassword" onkeydown="fncKeyStop(event);" onpaste="return false;" oncontextmenu="return false;" style="width:293px;color:#ffffff;">
jonnyhe 2015-08-12
  • 打赏
  • 举报
回复
它密码输入框是这样的:

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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