procedure TForm1.Button1Click(Sender: TObject); var Doc:IHTMLDocument2; input:OleVariant; userinputelement,pwdinputelement:ihtmlinputelement; begin doc:=webbrowser1.document as ihtmldocument2; userinputelement:=(doc.all.item(''user''(也就是网页中用户名控件的名字),0) as ihtmlinputelement); userinputelement.value:=edit1.text;(也就是你要向网页输入的东西) pwdinputelement:=(doc.all.item(''password'',0) as ihtmlinputelement); pwdinputelement.value:=edit2.text; input:=doc.all.item(''submit'',0); input.click; end;
当提交数据按钮没有NAME属性时,采用如下方法:
procedure TForm1.Button1Click(Sender: TObject); var Doc:IHTMLDocument2; form:ithmlformelement; userinputelement,pwdinputelement:ihtmlinputelement; begin doc:=webbrowser1.document as ihtmldocument2; userinputelement:=(doc.all.item(''user''(也就是网页中用户名控件的名字),0) as ihtmlinputelement); userinputelement.value:=edit1.text;(也就是你要向网页输入的东西) pwdinputelement:=(doc.all.item(''password'',0) as ihtmlinputelement); pwdinputelement:=edit2.text; form:=(doc.all.item(''login_form'',0) as ihtmlformelement):form.submit; end;