unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, Buttons;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
WebBrowser1: TWebBrowser;
Memo1: TMemo;
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses mshtml;
{$R *.dfm}
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
var
i,j:integer;
doc:IHtmlDocument2;
elec:IHtmlElementCollection;
chele:IHtmlElement;
inputelement:IHtmlInputElement;
textareaelement:IHtmlTextAreaElement;
formelement:IHtmlFormElement;
begin
doc:=webbrowser1.document as IHtmlDocument2;
if doc=nil then exit;
memo1.Lines.Clear;
memo1.Text:=doc.body.outerText;
elec:=doc.all;
for i:=0 to elec.length-1 do
begin
chele:=elec.item(i,emptyparam) as IHtmlElement;
if chele.tagName='INPUT' then
try
inputelement:=elec.item(i,emptyParam) as IHtmlInputElement;
if inputelement.name='userid' then inputelement.value:='用户名';
if inputelement.name='passwd' then inputelement.value:='口令';
except
end;
end;
for j:=0 to elec.length-1 do
begin
chele:=elec.item(j,emptyparam) as IHtmlElement;
if chele.tagName='FORM' then
try
formelement:=elec.item(j,emptyparam) as Ihtmlformelement;
if formelement.name='loginForm' then
begin
formelement.submit;
//showmessage('ok');
end;
except
end;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
webbrowser1.Navigate('http://www.abc.com/login.do');
end;
end.