同上例類似, 通過 'http://clIEnts1.google.cn/complete/search?&q=' + "關鍵字" 可以獲取 Google 的關鍵字搜索排名.
我用 Delphi 為關鍵字得到的結果是:
window.google.ac.h(
["Delphi",[
["Delphi 教程", "375,000 結果", "0"],
["Delphi盒子", "74,900 結果", "1"],
["Delphi 下載", "1,580,000 結果", "2"],
["Delphi7 下載", "1,600,000 結果", "3"],
["Delphi是什麼", "497,000 結果", "4"],
["Delphi 字符串函數", "352,000 結果", "5"],
["Delphi7 序列號", "302,000 結果", "6"],
["Delphi2009下載", "20,600 結果", "7"],
["Delphi7", "1,330,000 結果","8"],
["Delphi2009正式版下載", "5,710 結果", "9"]
]
]
)
上面結果以 window.google.ac.h(...) 的形式給出, 下面的操作關鍵就是給 ISuperObject 一個名為 "window.google.ac.h" 的方法, 並指向自定義的過程, 並在過程中完成解析.
運行效果圖:
代碼文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses MsXML, SuperObject;
function ToUTF8Encode(str: string): string;
var
b: Byte;
begin
for b in BytesOf(UTF8Encode(str)) do
Result := Format('%s%s%.2x', [Result, '%', b]);
end;
procedure Proc(const This, Params: ISuperObject; var Result: ISuperObject);
var
jo: ISuperObject;
begin
Form1.Memo1.Clear;
for jo in Params['1'] do with Form1.Memo1.Lines do
Form1.Memo1.Lines.Add(jo.format('%2%: %0% - %1%'));
end;
procedure TForm1.Button1Click(Sender: TObject);
const
u = 'http://clIEnts1.google.cn/complete/search?&q=';
var
jo: ISuperObject;
req: IXMLHTTPRequest;
url: WideString;
begin
jo := SO;
jo.M['window.google.ac.h'] := @Proc;
url := u + ToUTF8Encode(Edit1.Text);
req := CoXMLHTTP.Create;
req.open('Get', url, False, EmptyParam, EmptyParam);
req.send(EmptyParam);
jo[req.responseText];
end;
end.