Autor Beitrag
Sylvus
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 195



BeitragVerfasst: Sa 30.05.09 15:12 
Hay Leute,
hab gerade versucht ein Programm zu schreiben was den Platz einer Webseite bei Google raus finden soll. Aber leider erlaubt Google nicht, dass man die Suchergebnisse im Programm auswerten kann. Also wenn ich den Quellcode anfordere bekomme ich nur ein "Status 403". Wollte jetzt mal fragen, ob ihr einen Weg wisst, wie man über Delphi die Position bei einem bestimmten Suchbegriff abfragen kann.
Vielen Dank!
Grüße Sylvus
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Sa 30.05.09 15:24 
Wie lautet denn deine Abfrage?
Sylvus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 195



BeitragVerfasst: Sa 30.05.09 15:35 
naja benutzte die WinInet Komponente und das ganze sieht so aus:

ausblenden volle Höhe Delphi-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:
...
   google := 'http://www.google.com/search?q=' + Edit1.Text + '&start=' + inttostr(I) ;
   Quell := GetHTML(google);
...

function GetHTML(AUrl: string): string;
var
   databuffer: array[0..5000of char;
   ResStr: string;
   hSession, hfile: hInternet;
   dwindex, dwcodelen, dwread, dwNumber: cardinal;
   dwcode: array[1..20of char;
   res: pchar;
   Str: pchar;
begin
   ResStr := '';
   Result := '';
   if pos('http://', lowercase(AUrl)) = 0 then
      AUrl := 'http://' + AUrl;
   hSession := InternetOpen('InetURL:/1.0',
      INTERNET_OPEN_TYPE_PRECONFIG,
      nil,
      nil,
      0);
   if assigned(hSession) then try
      hfile := InternetOpenUrl(
         hsession,
         pchar(AUrl),
         nil,
         0,
         INTERNET_FLAG_RELOAD,
         0);
      if assigned(hfile) then try
         dwIndex := 0;
         dwCodeLen := 10;
         HttpQueryInfo(hfile,
            HTTP_QUERY_STATUS_CODE,
            @dwcode,
            dwcodeLen,
            dwIndex);
         res := pchar(@dwcode);
         dwNumber := sizeof(databuffer) - 1;
         if (res = '200'or (res = '302'then begin
            while (InternetReadfile(hfile, @databuffer, dwNumber, DwRead)) and (dwRead <> 0do begin
               databuffer[dwread] := #0;
               Str := pchar(@databuffer);
               resStr := resStr + Str;
               Application.ProcessMessages;
            end;
         end else
            ResStr := 'Status:' + res;
      finally
         InternetCloseHandle(hfile);
      end;
   finally
      InternetCloseHandle(hsession);
   end;
   Result := ResStr;
end;


Edit1.Text ist einfach soetwas wie hallowelt und I ist 0 und steigt dann also 10,20,30... um immer neue Ergebnisse anzuzeigen!
Grüße Sylvus
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Sa 30.05.09 15:55 
Hast du es schonmal mit UrlDownloadToFile probiert? Oder alternativ die Indys? Wenn nicht, dann probier das mal, weil die Möglichkeiten bei mir funktionieren.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19321
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 30.05.09 16:26 
403 ist glaube ich der Code für eine permanente Weiterleitung, z.B. von google.de auf www.google.de oder so.

Mit TIdHttp z.B. muss man da nur MyIdHttp.HandleRedirects := True setzen, fertig. Gibt es denn einen Grund weshalb du statt der paar Zeilen mit IdHttp lieber einen solchen Aufwand betreibst (vom Code her)?
Sylvus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 195



BeitragVerfasst: Sa 30.05.09 16:30 
ja weil ich das ganze anders unter Delphi 2005 irgendwie nicht schaffe... Aber ich schau grad mal wgeen DownloadToFile.... :) Danke schonmal!
Grüße Sylvus
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19321
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 30.05.09 16:35 
Ja, in der Delphi 2005 Personal musst du Indy erst nachinstallieren, in Turbo Delphi könntest du es einfach verwenden.

user profile iconSylvus hat folgendes geschrieben Zum zitierten Posting springen:
Aber ich schau grad mal wgeen DownloadToFile.... :)
Ich vermute, dass das gleiche passiert. Weiterleitung ist Weiterleitung...

// EDIT:
Nein, 403 bedeutet Zugriff verweigert, ich hab das mit 303 verwechselt. Was auch kein Wunder ist, im Ergebnis steht ein Hinweis auf:
www.google.com/terms_of_service.html
Zitat:
Es ist Ihnen untersagt, auf die Dienste in automatisierter Weise zuzugreifen, beispielsweise mit Robots oder Scripts.

Ich weiß zwar wie man das umgehen kann, aber wenn es in den Nutzungsbedingungen verboten ist, dann ist das eben so...

Das "Status 403" kommt ja aus deinem Quelltext, weil falsche Statuscodes ja abgefangen werden...
Sylvus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 195



BeitragVerfasst: So 31.05.09 02:05 
wenn es verboten ist, will ich das auch gar nicht, aber gibt es nen legalen Weg rauszufinden, wo sich eine Webseite bei einem Suchewort befindet?
Grüße Sylvus