Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#5

AW: Google Suchergebnisse abfragen

  Alt 17. Jun 2013, 22:47
Delphi-Quellcode:
// Callback Procedure (siehe superobject.pas Zeile 164)
procedure response(const This, Params: ISuperObject; var Result: ISuperObject);
var
  obj: ISuperObject;
begin
  with SearchForm.ResultList.Items do
  begin
    BeginUpdate;
    try
      Clear;
      case Params.I['responseStatus'] of
        200:
          for obj in Params['responseData.results'] do
            Add(obj.Format('%visibleUrl% - (%unescapedUrl%)'));
        else
          Add(Params.S['responseDetails']);
      end;
    finally
      EndUpdate;
    end;
  end;
end;

procedure TSearchForm.goClick(Sender: TObject);
var
  req: IXMLHttpRequest;
  o: ISuperObject;
begin
  req := {$IFDEF VER210}CoXMLHTTP{$ELSE}CoXMLHTTPRequest{$ENDIF}.Create;
  // Suche bei Google (callback=response)
  // Rückgabe ist "response(<JSON-Objekt mit den Suchergebnissen>)"
  req.open('GET', 'http://www.google.com/uds/GwebSearch?callback=response&rsz=large&v=1.0&q='+ UTF8Encode(GSearch.Text), false, EmptyParam, EmptyParam);
  req.send(EmptyParam);
  // leeres Objekt erzeugen
  o := so;
  // Callback Prozedur zuweisen
  o.M['response'] := response;
  // Da der zurückgelieferte Wert so aussieht "response(...)" und das Objekt eine Methode "response" kennt
  // wird diese Methode und damit die Callback-Prozedur ausgeführt
  o[req.responseText];
end;
Den Rest solltest du mit dem Debugger und der Doku herausbekommen

Schau dir auf jeden Fall mal den Wert von req.responseText im Debugger an.

Suche nach "Delphi"
Code:
response({
   "responseData":{
      "results":[
         {
            "GsearchResultClass":"GwebSearch",
            "unescapedUrl":"http://delphi.com/",
            "url":"http://delphi.com/",
            "visibleUrl":"delphi.com",
            "cacheUrl":"http://www.google.com/search?q\u003dcache:BD49F_np05UJ:delphi.com",
            "title":"\u003cb\u003eDelphi\u003c/b\u003e is a leading global supplier of electronics and technologies \u003cb\u003e...\u003c/b\u003e",
            "titleNoFormatting":"Delphi is a leading global supplier of electronics and technologies ...",
            "content":"Operating major technical centers, manufacturing sites and customer supportfacilities in 30 countries, \u003cb\u003eDelphi\u003c/b\u003e delivers real-world innovations that make  products \u003cb\u003e...\u003c/b\u003e"
         },
         {
            "GsearchResultClass":"GwebSearch",
            "unescapedUrl":"http://en.wikipedia.org/wiki/Delphi",
            "url":"http://en.wikipedia.org/wiki/Delphi",
            "visibleUrl":"en.wikipedia.org",
            "cacheUrl":"http://www.google.com/search?q\u003dcache:p7yTAyPO4zgJ:en.wikipedia.org",
            "title":"\u003cb\u003eDelphi\u003c/b\u003e - Wikipedia, the free encyclopedia",
            "titleNoFormatting":"Delphi - Wikipedia, the free encyclopedia",
            "content":"\u003cb\u003eDelphi\u003c/b\u003e 1] is both an archaeological site and a modern town inGreece on the  south-western spur of Mount Parnassus in the valley of Phocis. \u003cb\u003eDelphi\u003c/b\u003e was the  site \u003cb\u003e...\u003c/b\u003e"
         },
         {
            "GsearchResultClass":"GwebSearch",
            "unescapedUrl":"http://www.embarcadero.com/products/delphi",
            "url":"http://www.embarcadero.com/products/delphi",
            "visibleUrl":"www.embarcadero.com",
            "cacheUrl":"http://www.google.com/search?q\u003dcache:qhbs64-Zd6MJ:www.embarcadero.com",
            "title":"\u003cb\u003eDelphi\u003c/b\u003e XE4 | Develop Apps for iOS, Windows and Mac",
            "titleNoFormatting":"Delphi XE4 | DevelopApps for iOS, Windows and Mac",
            "content":"\u003cb\u003eDelphi\u003c/b\u003e XE4- the multi-device, true native app development solution for iOS,  Windows andMac."
         },
         {
            "GsearchResultClass":"GwebSearch",
            "unescapedUrl":"http://www.delphiforums.com/",
            "url":"http://www.delphiforums.com/",
            "visibleUrl":"www.delphiforums.com",
            "cacheUrl":"http://www.google.com/search?q\u003dcache:i-8mt-uNXBMJ:www.delphiforums.com",
            "title":"\u003cb\u003eDelphi\u003c/b\u003e Forums: Communities for friends, groups and businesses",
            "titleNoFormatting":"Delphi Forums: Communities for friends, groups and businesses",
            "content":"Create your free forum on \u003cb\u003eDelphi\u003c/b\u003e Forums, the leading network of user-created,  user-managed communities for groups, organizations, businesses, and people \u003cb\u003e...\u003c/b\u003e"
         },
         {
            "GsearchResultClass":"GwebSearch",
            "unescapedUrl":"http://www.ancient-greece.org/archaeology/delphi-archaeology.html",
            "url":"http://www.ancient-greece.org/archaeology/delphi-archaeology.html",
            "visibleUrl":"www.ancient-greece.org",
            "cacheUrl":"http://www.google.com/search?q\u003dcache:F1tBLROtmA0J:www.ancient-greece.org",
            "title":"\u003cb\u003eDelphi\u003c/b\u003e - Ancient-Greece.org",
            "titleNoFormatting":"Delphi - Ancient-Greece.org",
            "content":"The archaeological site of \u003cb\u003eDelphi\u003c/b\u003e is one of the most important ancient relics of  Greece. The magnitude of the \u003cb\u003eDelphi\u003c/b\u003e contributions to the entire ancient  civilization \u003cb\u003e...\u003c/b\u003e"
         },
         {
            "GsearchResultClass":"GwebSearch",
            "unescapedUrl":"http://www.delphiglass.com/",
            "url":"http://www.delphiglass.com/",
            "visibleUrl":"www.delphiglass.com",
            "cacheUrl":"http://www.google.com/search?q\u003dcache:eggE6s9go-oJ:www.delphiglass.com",
            "title":"Stained Glass Supplies, Fusing Supplies At \u003cb\u003eDelphi\u003c/b\u003e Glass",
            "titleNoFormatting":"Stained Glass Supplies, Fusing Supplies At Delphi Glass",
            "content":"Stained Glass Supplies, Fusing Supplies, Flameworking \u0026amp; More at \u003cb\u003eDelphi\u003c/b\u003e Glass."
         },
         {
            "GsearchResultClass":"GwebSearch",
            "unescapedUrl":"http://delphi.about.com/",
            "url":"http://delphi.about.com/",
            "visibleUrl":"delphi.about.com",
            "cacheUrl":"http://www.google.com/search?q\u003dcache:rbXWRXtYbK8J:delphi.about.com",
            "title":"About \u003cb\u003eDelphi\u003c/b\u003e Programming - For Novice and Expert Embarcadero \u003cb\u003e...\u003c/b\u003e",
            "titleNoFormatting":"About Delphi Programming - For Novice and Expert Embarcadero ...",
            "content":"Jan 3, 2013 \u003cb\u003e...\u003c/b\u003e Are you a beginner or expert \u003cb\u003eDelphi\u003c/b\u003e developer? Looking for how to get started or  need advice and help for a quick solution to your daily \u003cb\u003eDelphi\u003c/b\u003e \u003cb\u003e...\u003c/b\u003e"
         },
         {
            "GsearchResultClass":"GwebSearch",
            "unescapedUrl":"http://www.cityofdelphi.org/",
            "url":"http://www.cityofdelphi.org/",
            "visibleUrl":"www.cityofdelphi.org",
            "cacheUrl":"http://www.google.com/search?q\u003dcache:vcmJ8nlpArEJ:www.cityofdelphi.org",
            "title":"City of \u003cb\u003eDelphi\u003c/b\u003e - Welcome to the City of \u003cb\u003eDelphi\u003c/b\u003e!",
            "titleNoFormatting":"City of Delphi - Welcome to the City of Delphi!",
            "content":"Welcome to the City of \u003cb\u003eDelphi\u003c/b\u003e, Indiana. \u003cb\u003eDelphi\u003c/b\u003e was chosen as a stellar  community in 2012. Explore our storied past and stellar future."
         }
      ],
      "cursor":{
         "resultCount":"9,610,000",
         "pages":[
            {
               "start":"0",
               "label":1
            },
            {
               "start":"8",
               "label":2
            },
            {
               "start":"16",
               "label":3
            },
            {
               "start":"24",
               "label":4
            },
            {
               "start":"32",
               "label":5
            },
            {
               "start":"40",
               "label":6
            },
            {
               "start":"48",
               "label":7
            },
            {
               "start":"56",
               "label":8
            }
         ],
         "estimatedResultCount":"9610000",
         "currentPageIndex":0,
         "moreResultsUrl":"http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d0\u0026hl\u003den\u0026q\u003dDelphi",
         "searchResultTime":"0.24"
      }
   },
   "responseDetails":null,
   "responseStatus":200
})
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)

Geändert von Sir Rufo (18. Jun 2013 um 00:43 Uhr)
  Mit Zitat antworten Zitat