Autor Beitrag
DaKrissX84
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Mo 03.03.03 16:09 
Hi!

Wie kann man mit Delphi eine Internetseite "steuern"?

Das Programm soll automatisch meinen Yahoo-Posteingang öffnen, und per POS die Stelle suchen und ausgeben, an der steht, wie viele neue E-Mails angekommen sind.

Das Problem:
Manchmal ist es erforderlich, sein Passwort einzugeben, bevor man auf die Posteingangsseite kommt. Das Programm soll dann das "Edit" dieser Eingabemaske erkennen und automatisch mein Passwort eingeben und "submit" klicken.

Geht das irgendwie mit dem TWebbrowser? (Über "Item" oder so?) Wenn ja, wie??

Vielen Dank im Voraus!
Matthias
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 121



BeitragVerfasst: Di 04.03.03 15:13 
Hallo,

ich habe hier mal zwei "Code-Schnipsel". Das erste füllt ein Edit Feld und gibt true zurück, wenn es vorhanden ist. Das zweite betätigt einen Button.
Diese Lösung kommt auch mit mehreren Frames zurecht. Die Ursprungsversion stammt, glaub ich jedenfalls :nixweiss: , aus dem Swiss Delphi Center.

ciao

Matthias

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
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;

function BtnClick(WebBrowser: TWebBrowser; FieldName: 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, click button
        if FormItem.Item(j).Name = FieldName then
        begin
          FormItem.Item(j).Click;
          Result := True;
        end;
      except
        Exit;
      end;
    end;
  end;
end;
DaKrissX84 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Di 04.03.03 17:57 
Vielen Dank erstma!
Jetzt binnich schomma einen Schritt weiter...

Allerdings:

Da ich relativ blutiger Anfänger auf dem Gebiet Delphi bin:
Ich weiss nicht genau welche Parameter ich nun jeweils angeben soll, wenn ich einer der Funktionen aufrufen will, die du gepostet hast...

Fieldname....muss da sowas hin wie "Input"?? oder sogar der Name des Inputs?
Value.....Kann ich mir auch nicht wirklich was drunter vorstellen. Vielleicht die Value eines Eingabefeldes? Aber warum als String??

Gehe ich recht in der Annahme, dass diese beiden Funktionen NUR funzen, wenn man die Namen der Eingabefelder bzw. Buttons im Quelltext gegeben hat?

Vielen Dank nochmal für deine Mühe und sorry für die Umstände!
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Di 04.03.03 19:12 
Ich denke den namen des inputs...musst mal in der html nachkucken. Entweder name='xxx' ode id='xxx' sind die attribute eines tags, in der die IDs vergeben werden.

Hoffe es hilft.
DaKrissX84 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Di 04.03.03 19:30 
Hi!

Danke erstma!

Also:
In meinem Fall heisst der Input "Passwort_Check". Leider kommt da beim compilieren die Fehlermeldung:
Undefinierter Bezeichner: Passwort_Check

Also ist "Fieldname" vielleicht doch nicht der name des Inputs?

Und: Leider muss ich auch noch wissen was der Parameter "Value" bedeuten soll, bevor ich (endlich) weitermachen kann...

thanx
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Di 04.03.03 23:15 
'Value' ist das was dann da drinn ist.

zB: <input type="text" name="xname" value="Mr. X"> erzeugt ein edit-feld, mit dem namen 'xname' und dem inhalt 'Mr. X'
Matthias
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 121



BeitragVerfasst: Di 04.03.03 23:30 
Hy,

jupp, ich denke Du hast recht. Nehmen wir mal an an du hast ein edit feld mit dem Name password, dann könnte der Code so aussehen.

ausblenden Quelltext
1:
2:
3:
if FillForm(WebBrowser1, 'password', 'meinpasswort')
then
  BtnClick(WebBrowser1, 'submit');


Value ist also das, was in das Editfeld hinein soll.

Matthias
DaKrissX84 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Mi 05.03.03 00:23 
Super!
Vielen Dank, klappt bestens!! :D