chenybin给偶的代码,帖一下就结帐拉:)
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, OleCtrls, SHDocVw, MSHTML;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure WebBrowser1DownloadComplete(Sender: TObject);
private
{ Private declarations }
FDownComplete : Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
ovDoc, ovInput, ovTag: OleVariant;
I : Integer;
begin
if not FDownComplete then Application.MessageBox('网页正在下载中,请稍后……', '提示', MB_OK + MB_ICONINFORMATION)
else begin
ovDoc := WebBrowser1.Document;
ovInput := ovDoc.all.tags('INPUT');
for I := 0 to ovInput.length -1 do begin
ovTag := ovInput.item(I);
if (ovTag.Type = 'text') or (ovTag.Type = 'password') then begin
if ovTag.Name = 'uid' then ovTag.Value := 'chenybi';
if ovTag.Name = 'passwd' then ovTag.Value := '******';
end
else if ovTag.Type = 'image' then begin
if ovTag.alt = '登录ChinaRen' then
ovTag.Click;
end;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FDownComplete := False;
WebBrowser1.Navigate('http://www.chinaren.com');
end;
procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
begin
FDownComplete := True;
end;
end.