登录和模拟点击什么的都还还好处理,有些点击是使用链接的,那就修改我的程序里面的那个forms为links就可以了。我是用WebBrower做的,先放上来,看有用没有
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;
Button1: TButton;
Memo1: TMemo;
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure WebBrowser1DownloadComplete(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FDownComplete : Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
ovDoc, ovForm, ovInput, ovTag: OleVariant;
I : Integer;
begin
{chinaren
if not FDownComplete then Application.MessageBox('网页正在下载中,请稍后……', '提示', MB_OK + MB_ICONINFORMATION)
else begin
ovDoc := WebBrowser1.Document;
ovForm := ovDoc.forms;
for I := ovForm.length - 1 downto 0 do begin
if ovForm.item(I).Name = 'FM' then begin
ovInput := ovform.Item(I);
Break;
end;
end;
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 := 'chenybin';
if ovTag.Name = 'passwd' then ovTag.Value := '******';
end
else if ovTag.Type = 'image' then begin
if ovTag.alt = '登录ChinaRen' then
ovTag.Click;
end;
end;
//ovInput.Submit;
end;
}
if not FDownComplete then Application.MessageBox('网页正在下载中,请稍后……', '提示', MB_OK + MB_ICONINFORMATION)
else begin
ovDoc := WebBrowser1.Document;
ovForm := ovDoc.forms;
for I := ovForm.length - 1 downto 0 do begin
if ovForm.item(I).Name = 'form' then begin
ovInput := ovform.Item(I);
Break;
end;
end;
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 = 'user' then ovTag.Value := 'chenybin';
if ovTag.Name = 'pass' then ovTag.Value := 'xxxxxx';
end
else if (ovTag.Type = 'submit') and (ovTag.Name = 'enter.x') then begin
//if ovTag.alt = '登录ChinaRen' then
ovTag.Click;
end;
end;
//ovInput.Submit;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FDownComplete := False;
//WebBrowser1.Navigate('http://www.cng.com.cn/');
//WebBrowser1.Navigate('http://www.chinaren.com/');
WebBrowser1.Navigate('http://www.126.com/');
end;
procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
begin
FDownComplete := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ovDoc, ovForms, ovForm, ovInput: OleVariant;
I, J : Integer;
begin
if not FDownComplete then Application.MessageBox('网页正在下载中,请稍后……', '提示', MB_OK + MB_ICONINFORMATION)
else begin
ovDoc := WebBrowser1.Document;
ovForms := ovDoc.all.tags('FORM');
for I := 0 to ovForms.length -1 do begin
ovForm := ovForms.item(I);
if AnsiSameText(ovForm.action, 'vote/fivote.asp?voteID=17') then begin
for J := 0 to ovForm.length - 1 do begin
ovInput := ovForm.item(J);
Memo1.Lines.Add(ovInput.Type);
if (ovInput.Type = 'radio') then begin
// 下面的这个113是从网页里面找出来的,分别是113,114,115
if (ovInput.Value = '113') and (ovInput.Name = 'ID') then begin
ovInput.Checked := True;
ovForm.submit;
Break;
end;
end
end;
end;
end;
end;
end;
end.
object Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Memo1: TMemo
Left = 468
Top = 264
Width = 185
Height = 89
ImeName = #20013#25991' ('#31616#20307') - '#25340#38899#21152#21152'3.11'
Lines.Strings = (
'Memo1')
TabOrder = 3
end
object WebBrowser1: TWebBrowser
Left = 16
Top = 12
Width = 433
Height = 381
TabOrder = 0
OnDownloadComplete = WebBrowser1DownloadComplete
ControlData = {
4C000000C02C0000612700000000000000000000000000000000000000000000
000000004C000000000000000000000001000000E0D057007335CF11AE690800
2B2E126208000000000000004C0000000114020000000000C000000000000046
8000000000000000000000000000000000000000000000000000000000000000
00000000000000000100000000000000000000000000000000000000}
end
object BitBtn1: TBitBtn
Left = 220
Top = 412
Width = 75
Height = 25
Caption = #26657#21451#24405#30331#24405
TabOrder = 1
OnClick = BitBtn1Click
end
object Button1: TButton
Left = 356
Top = 412
Width = 75
Height = 25
Caption = #38142#25509#25237#31080
TabOrder = 2
OnClick = Button1Click
end
end