delphi_ishodnik_zapolnenie_form.zip
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
Label5: TLabel;
Edit5: TEdit;
Label6: TLabel;
Edit6: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('http://web.tak.ru/registuser.php');
end;
procedure BClick(WebBrowser: TWebBrowser; BFieldName: string);
var
i: Integer;
html_tag: variant;
begin
html_tag:=WebBrowser.OleObject.Document.forms.item(0).elements;
for i:=0 to (html_tag.length-1) do
begin
if (html_tag.item(i).value=BFieldName) then
html_tag.item(i).click;
end;
end;
function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
i, j: Integer;
FormItem: Variant;
begin
Result := False;
//no form on document
if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
begin
Exit;
end;
//count forms on document
for I := 0 to WebBrowser.OleObject.Document.forms.Length — 1 do
begin
FormItem := WebBrowser.OleObject.Document.forms.Item(I);
for j := 0 to FormItem.Length — 1 do
begin
try
//when the fieldname is found, try to fill out
if FormItem.Item(j).Name = FieldName then
begin
FormItem.Item(j).Value := Value;
Result := True;
end;
except
Exit;
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FillForm(WebBrowser1, 'login', edit1.Text); //Логин
FillForm(WebBrowser1, 'name', edit2.Text); //ФИО
FillForm(WebBrowser1, 'email', edit3.Text); //Почта
FillForm(WebBrowser1, 'password', edit4.Text); //Пароль
FillForm(WebBrowser1, 'passwordtoo', edit5.Text); //Повторите пароль
if FillForm(WebBrowser1, 'form', 'TRIALANET.RU') = False then
ShowMessage('Ошибка! Поле "form" не найденно!');
FillForm(WebBrowser1, 'keystring', edit6.Text); //Каптча
BClick(WebBrowser1, 'Зарегистрироваться'); //Кнопка регистрации
end;
end.