كيف نعمل Autofill Forms
#1
اود عمل برنامج يؤدي وضيفة مشابهة ل Autofill Forms
وذلك لعمل email او تسجيل في اي موقع
هل لديكم افكار او نصائح او امثلة او مشاريع بهذا الخصوص
الموصوع مهم للغاية
========================
اعتقد ان record يتصمن عدة حقول
ولكن كيف نرسلها الى حقل في الموقع
========================
[صورة: picture0002l.png]
الرد
#2
مثال على الموقع
كود :
User account Username: * E-mail address: * Personal Address: City: Country: * Website: CAPTCHA: <label for="edit-name"> <input type="text" maxlength="60" name="name" id="edit-name" size="60" value="" class="form-text required"/> <label for="edit-mail"> <input type="text" maxlength="64" name="mail" id="edit-mail" size="60" value="" class="form-text required"/> <label for="edit-profile-address"> <input type="text" maxlength="255" name="profile_address" id="edit-profile-address" size="60" value="" class="form-text"/> <label for="edit-profile-city"> <input type="text" maxlength="255" name="profile_city" id="edit-profile-city" size="60" value="" class="form-text"/> <label for="edit-profile-country"> <select name="profile_country" class="form-select required" id="edit-profile-country"> <label for="edit-profile-website"> <input type="text" maxlength="255" name="profile_website" id="edit-profile-website" size="60" value="" class="form-text"/> <label for="edit-captcha-response"> What is the first word in the phrase "awazap uxefane agoniqa zuxotal xuf"?: <span class="form-required" title="This field is required."> </label> <input type="text" maxlength="128" name="captcha_response" id="edit-captcha-response" size="15" value="" class="form-text required"/> </div> <input type="hidden" name="captcha_token" id="edit-captcha-token" value="af342a85c05b358b0741e9c68cbdb4bf"/> </fieldset> <input type="submit" name="op" id="edit-submit" value="Create new account" class="form-submit"/> <input type="submit" name="op" id="edit-submit" value="Create new account" class="form-submit"/>

hxxp://www.msegui.org/user/register
الرد
#3
وجدت مثال
كود :
Title: automatic fill out HTML forms with TWebBrowser? { To test this code put a TWebBrowser and A TButton component on the form } 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; //When the document is complete try to fill out the field homepage with the url procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); begin if FillForm(WebBrowser1, 'homepage', 'http://www.swissdelphicenter.ch') = False then ShowMessage('Error. Field not available or no Form found.'); end; // Show the Webbrowser-Progress in Label1 procedure TForm1.WebBrowser1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer); begin if ProgressMax = 0 then begin label1.Caption := ''; Exit; end; try if (Progress -1) and (Progress then label1.Caption := IntToStr((Progress * 100) div ProgressMax) + '% loaded...' else label1.Caption := ''; except on EDivByZero do Exit; end; end; //For example you can load the page /en/addtip.php to the TWebBrowser //When the document is Complete the form where you can put your homepage //address is filled out procedure TForm1.Button1Click(Sender: TObject); begin Webbrowser1.Navigate('http://www.swissdelphicenter.ch/en/addtip.php'); // Show the Titel of the currently active Webpage in the titlebar // Den Titel der aktuellen Webseite in der Titeleiste anzeigen Caption := Webbrowser1.OleObject.Document.Title; end;
الرد
#4
وهذا مثال 2
كود :
Title: automatically fill in web forms of a running IE instance? { This example shows how to automatically fill in a search string in the "Search Tip" page and click the search button. } uses MSHTML_TLB; // first navigate to tipspage procedure TForm1.Button1Click(Sender: TObject); begin Webbrowser1.Navigate('http://www.swissdelphicenter.ch/en/tipsuchen.php'); end; // Try to access IE instance and fill out the search field with // a text and click the search button procedure TForm1.Button3Click(Sender: TObject); var hIE: HWND; ShellWindow: IShellWindows; WB: IWebbrowser2; spDisp: IDispatch; IDoc1: IHTMLDocument2; Document: Variant; k, m: Integer; ovElements: OleVariant; i: Integer; begin ShellWindow := CoShellWindows.Create; // get the running instance of Internet Explorer for k := 0 to ShellWindow.Count do begin spDisp := ShellWindow.Item(k); if spDisp = nil then Continue; // QueryInterface determines if an interface can be used with an object spDisp.QueryInterface(iWebBrowser2, WB); if WB nil then begin WB.Document.QueryInterface(IHTMLDocument2, iDoc1); if iDoc1 nil then begin WB := ShellWindow.Item(k) as IWebbrowser2; begin Document := WB.Document; // count forms on document and iterate through its forms for m := 0 to Document.forms.Length - 1 do begin ovElements := Document.forms.Item(m).elements; // iterate through elements for i := 0 to ovElements.Length - 1 do begin // when input fieldname is found, try to fill out try if (CompareText(ovElements.item(i).tagName, 'INPUT') = 0) and (CompareText(ovElements.item(i).type, 'text') = 0) then begin ovElements.item(i).Value := 'FindWindow'; end; except end; // when Submit button is found, try to click try if (CompareText(ovElements.item(i).tagName, 'INPUT') = 0) and (CompareText(ovElements.item(i).type, 'SUBMIT') = 0) and (ovElements.item(i).Value = 'Search') then // Suchen f r German begin ovElements.item(i).Click; end; except end; end; end; end; end; end; end; end;
الرد
#5
وهذا اخر
كود :
Title: How to execute a Javascript function in a Webbrowser/ IE Document uses MSHTML_TLB, SHDocVw, ShellAPI; // function to execute a script function function ExecuteScript(doc: IHTMLDocument2; script: string; language: string): Boolean; var win: IHTMLWindow2; Olelanguage: Olevariant; begin if doc nil then begin try win := doc.parentWindow; if win nil then begin try Olelanguage := language; win.ExecScript(script, Olelanguage); finally win := nil; end; end; finally doc := nil; end; end; end; Usage Examples: 1. how to login to gmx homepage procedure FillInGMXForms(WB: ShDocVW_TLB.IWebbrowser2; IDoc1: IHTMLDocument2; Document: Variant; AKennung, APasswort: string); const IEFields: array[1..4] of string = ('INPUT', 'text', 'INPUT', 'password'); var IEFieldsCounter: Integer; i: Integer; m: Integer; ovElements: OleVariant; begin if Pos('GMX - Homepage', Document.Title) 0 then while WB.ReadyState READYSTATE_COMPLETE do Application.ProcessMessages; // count forms on document and iterate through its forms IEFieldsCounter := 0; for m := 0 to Document.forms.Length - 1 do begin ovElements := Document.forms.Item(m).elements; // iterate through elements for i := ovElements.Length - 1 downto 0 do begin try // if input fields found, try to fill them out if (ovElements.item(i).tagName = IEFields[1]) and (ovElements.item(i).type = IEFields[2]) then begin ovElements.item(i).Value := AKennung; Inc(IEFieldsCounter); end; if (ovElements.item(i).tagName = IEFields[3]) and (ovElements.item(i).type = IEFields[4]) then begin ovElements.item(i).Value := APasswort; Inc(IEFieldsCounter); end; except // failed... end; end; { for i...} end; { for m } // if the fields are filled in, submit. if IEFieldsCounter = 3 then ExecuteScript(iDoc1, 'document.login.submit()', 'JavaScript'); end; function LoginGMX_IE(AKennung, APasswort: string): Boolean; var ShellWindow: IShellWindows; WB: ShDocVW_TLB.IWebbrowser2; spDisp: IDispatch; IDoc1: IHTMLDocument2; Document: Variant; k: Integer; begin ShellWindow := CoShellWindows.Create; // get the running instance of Internet Explorer for k := 0 to ShellWindow.Count do begin spDisp := ShellWindow.Item(k); if spDisp = nil then Continue; // QueryInterface determines if an interface can be used with an object spDisp.QueryInterface(iWebBrowser2, WB); if WB nil then begin WB.Document.QueryInterface(IHTMLDocument2, iDoc1); if iDoc1 nil then begin WB := ShellWindow.Item(k) as ShDocVW_TLB.IWebbrowser2; Document := WB.Document; // if GMX page... FillInGMXForms(WB, IDoc1, Document, AKennung, APasswort); end; { idoc nil } end; { wb nil } end; { for k } end; Navigate to the gmx homepage in the IE browser an login procedure TForm1.Button1Click(Sender: TObject); begin ShellExecute(Handle, 'open', 'http://www.gmx.ch', nil, nil, SW_SHOW); Sleep(2000); LoginGMX_IE('user@gmx.net', 'pswd'); end; navigate to the gmx homepage in the Webbrowser an login procedure TForm1.Button2Click(Sender: TObject); var IDoc1: IHTMLDocument2; Web: ShDocVW_TLB.IWebBrowser2; begin Webbrowser1.Navigate('http://www.gmx.ch'); while Webbrowser1.ReadyState READYSTATE_COMPLETE do Application.ProcessMessages; Webbrowser1.Document.QueryInterface(IHTMLDocument2, iDoc1); Web := WebBrowser1.ControlInterface; FillInGMXForms(Web, iDoc1, Webbrowser1.Document, 'user@gmx.net', 'pswd'); end;
الرد


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم