XE3随笔17:实例 - 模拟 Google 搜索
本例测试效果图:

代码文件:
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; //这是将字符串转换成 UTF 编码的函数, 这里用于 Google 的搜索地址
function ToUTF8Encode(str: string): string;
var
b: Byte;
begin
for b in BytesOf(UTF8Encode(str)) do
Result := Format('%s%s%.2x', [Result, '%', b]);
end; //这是给 ISuperObject 准备的方法
procedure Proc(const This, Params: ISuperObject; var Result: ISuperObject);
var
jo: ISuperObject;
begin
Form1.Memo1.Clear;
for jo in Params['responseData.results'] do with Form1.Memo1.Lines do
begin
Add(jo.Format('%titleNoFormatting%:'));
Add(jo.Format('%unescapedUrl%'));
Add(EmptyStr);
end;
end; procedure TForm1.Button1Click(Sender: TObject);
const
u = 'http://www.google.cn/uds/GwebSearch?callback=response&rsz=large&v=1.0&q=';
var
jo: ISuperObject;
req: IXMLHTTPRequest;
url: WideString;
begin
jo := SO;
jo.M['response'] := @Proc; {搜索结果将是类似 response(...) 函数格式的字符串} url := u + ToUTF8Encode(Edit1.Text); {准备搜索地址} //搜索
req := CoXMLHTTP.Create;
req.open('Get', url, False, EmptyParam, EmptyParam);
req.send(EmptyParam); //搜索结果在 req.responseText(后付其全部内容), 下面语句将调用上面的 Proc 过程.
jo[req.responseText]; {这是在本系列"方法"一节用到的第二种调用方法}
end; end.
窗体文件:
object Form1: TForm1
Left =
Top =
Caption = 'Form1'
ClientHeight =
ClientWidth =
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch =
TextHeight =
object Memo1: TMemo
Left =
Top =
Width =
Height =
Align = alLeft
Lines.Strings = (
'Memo1')
ScrollBars = ssBoth
TabOrder =
ExplicitHeight =
end
object Button1: TButton
Left =
Top =
Width =
Height =
Caption = 'Button1'
TabOrder =
OnClick = Button1Click
end
object Edit1: TEdit
Left =
Top =
Width =
Height =
TabOrder =
Text = 'Delphi'
end
end
下面是我以 "Delphi" 为关键字搜索返回的 responseText, 可以做个搜索工具了:
response(
{
"responseStatus": 200,
"responseData": {
"cursor": {
"pages": [
{
"label": 1,
"start": "0"
},{
"label": 2,
"start": "8"
},{
"label": 3,
"start": "16"
},{
"label": 4,
"start": "24"
},{
"label": 5,
"start": "32"
},{
"label": 6,
"start": "40"
},{
"label": 7,
"start": "48"
},{
"label": 8,
"start": "56"
}],
"currentPageIndex": 0,
"estimatedResultCount": "6050000",
"moreResultsUrl": "http:\/\/www.google.cn\/search?oe=utf8&ie=utf8&source=uds&start=0&hl=zh-CN&q=Delphi"
},
"results": [
{
"titleNoFormatting": "『Delphi园地』-源码,控件,文档,工具,免费下载,建设专业Delphi资源平台",
"url": "http:\/\/www.delphifans.com\/",
"cacheUrl": "http:\/\/www.google.com\/search?q=cache:gxlSlu0OTqQJ:www.delphifans.com",
"GsearchResultClass": "GwebSearch",
"visibleUrl": "www.delphifans.com",
"content": "提供Delhpi技巧文章、源码、控件、文档、工具等。",
"title": "『<b>Delphi<\/b>园地』-源码,控件,文档,工具,免费下载,建设专业<b>Delphi<\/b>资源平台",
"unescapedUrl": "http:\/\/www.delphifans.com\/"
},{
"titleNoFormatting": "Delphi - 维基百科,自由的百科全书",
"url": "http:\/\/zh.wikipedia.org\/wiki\/Delphi",
"cacheUrl": "http:\/\/www.google.com\/search?q=cache:KPWnJZ_ZuuQJ:zh.wikipedia.org",
"GsearchResultClass": "GwebSearch",
"visibleUrl": "zh.wikipedia.org",
"content": "<b>Delphi<\/b>,是Windows平台下的著名快速应用程序开发工具(Rapid Application Development ,简称RAD)。它的前身是在DOS下的产品BorlandTurbo Pascal,最早的版本由 <b>...<\/b>",
"title": "<b>Delphi<\/b> - 维基百科,自由的百科全书",
"unescapedUrl": "http:\/\/zh.wikipedia.org\/wiki\/Delphi"
},{
"titleNoFormatting": "DELPHI盒子- Delphi源代码控件文档工具下载",
"url": "http:\/\/www.2ccc.com\/",
"cacheUrl": "http:\/\/www.google.com\/search?q=cache:CF650RgvoJkJ:www.2ccc.com",
"GsearchResultClass": "GwebSearch",
"visibleUrl": "www.2ccc.com",
"content": "<b>DELPHI<\/b>源代码、组件、例子、演示及相关工具下载,文档发布,全站包含论坛,笔记等功能 ,每天更新。",
"title": "<b>DELPHI<\/b>盒子- <b>Delphi<\/b>源代码控件文档工具下载",
"unescapedUrl": "http:\/\/www.2ccc.com\/"
},{
"titleNoFormatting": "编程中国>> 技术教程>> 开发语言>> Delphi",
"url": "http:\/\/www.bccn.net\/Article\/kfyy\/delphi\/",
"cacheUrl": "http:\/\/www.google.com\/search?q=cache:vjiBcr2xV14J:www.bccn.net",
"GsearchResultClass": "GwebSearch",
"visibleUrl": "www.bccn.net",
"content": "普通文章, 第二章<b>Delphi<\/b>面向对象的编程方法(一), 06-25. 普通文章 <b>...<\/b> 普通文章, 用 <b>Delphi<\/b>制作以浏览器为界面的应用程序, 08-30. 普通文章, <b>Delphi<\/b> 中串口通讯的实现 <b>...<\/b>",
"title": "编程中国>> 技术教程>> 开发语言>> <b>Delphi<\/b>",
"unescapedUrl": "http:\/\/www.bccn.net\/Article\/kfyy\/delphi\/"
},{
"titleNoFormatting": "Delphi is a leading global supplier for the automotive, computing ...",
"url": "http:\/\/www.delphi.com\/",
"cacheUrl": "http:\/\/www.google.com\/search?q=cache:r5kD35m3Ns0J:www.delphi.com",
"GsearchResultClass": "GwebSearch",
"visibleUrl": "www.delphi.com",
"content": "Supplier of audio systems, modules, and components to manufacturers and replacement parts to the after market worldwide.",
"title": "<b>Delphi<\/b> is a leading global supplier for the automotive, computing <b>...<\/b>",
"unescapedUrl": "http:\/\/www.delphi.com\/"
},{
"titleNoFormatting": "delphi 窑洞",
"url": "http:\/\/www.51delphi.com\/",
"cacheUrl": "http:\/\/www.google.com\/search?q=cache:Kgv5hBXmSFgJ:www.51delphi.com",
"GsearchResultClass": "GwebSearch",
"visibleUrl": "www.51delphi.com",
"content": "基于<b>Delphi<\/b> 的Rich Internet Application开发和应用平台 。 <b>...<\/b> 61449, <b>Delphi<\/b> 7的 Property OldCreateOrder does not exist(1786字节), javer007, 2009-10-12 14:42:48 <b>...<\/b>",
"title": "<b>delphi<\/b> 窑洞",
"unescapedUrl": "http:\/\/www.51delphi.com\/"
},{
"titleNoFormatting": "delphi专栏_软件开发_最专业的程序开发网站_开发者网络_软件_天极网",
"url": "http:\/\/dev.yesky.com\/ysdevdelphi\/",
"cacheUrl": "http:\/\/www.google.com\/search?q=cache:j-qd-w9ESrwJ:dev.yesky.com",
"GsearchResultClass": "GwebSearch",
"visibleUrl": "dev.yesky.com",
"content": "在<b>Delphi<\/b>数据库应用系统的数据录入过程中,有些数据是保存在Excel中的;有些是保存 <b>...<\/b> 为了便于开发数据库应用程序,在<b>Delphi<\/b>集成开发环境中,提供了大量的数据库工具 <b>...<\/b>",
"title": "<b>delphi<\/b>专栏_软件开发_最专业的程序开发网站_开发者网络_软件_天极网",
"unescapedUrl": "http:\/\/dev.yesky.com\/ysdevdelphi\/"
},{
"titleNoFormatting": "Delphi俱乐部",
"url": "http:\/\/www.tommstudio.com\/",
"cacheUrl": "http:\/\/www.google.com\/search?q=cache:9JQ4L48RA1QJ:www.tommstudio.com",
"GsearchResultClass": "GwebSearch",
"visibleUrl": "www.tommstudio.com",
"content": "dephi俱乐部,c#,<b>delphi<\/b>,<b>delphi<\/b>控件,<b>delphi<\/b>源码,<b>delphi<\/b>书籍,商业源码,程序开发,源码 交易,开发,方案, <b>...<\/b> Net,Java,PowerBuilder,PHP,ASP,PERL 免费源码下载,<b>Delphi<\/b>俱乐部 .",
"title": "<b>Delphi<\/b>俱乐部",
"unescapedUrl": "http:\/\/www.tommstudio.com\/"
}]
},
"responseDetails": null
}
)
XE3随笔17:实例 - 模拟 Google 搜索的更多相关文章
- Google搜索命令语法大全
以下是目前所有的Google搜索命令语法,它不同于Google的帮助文档,因为这里介绍 了几个Google不推荐使用的命令语法.大多数的Google搜索命令语法有它特有的使用格式,希望大家能正确使用. ...
- 关于python抓取google搜索结果的若干问题
关于python抓取google搜索结果的若干问题 前一段时间一直在研究如何用python抓取搜索引擎结果,在实现的过程中遇到了很多的问题,我把我遇到的问题都记录下来,希望以后遇到同样问题的童 ...
- GOOGLE搜索秘籍完全公开
一,GOOGLE简介 Google(www.google.com)是一个搜索引擎,由两个斯坦福大学博士生Larry Page与Sergey Brin于1998年9月发明,Google Inc. 于19 ...
- 复杂的1秒--图解Google搜索技术
谷歌(Google),一个非常成功,但又十分神秘,而且带有几分理想化色彩的互联网搜索巨人,它还是一家相当了不起的广告公司,谷歌首页上的那个搜索按钮是其年赢利200亿美元的杀手级应用,也是Interne ...
- 【转载】google搜索从入门到精通
原文地址:http://www.cnblogs.com/helloIT/articles/5095668.html /***************************************** ...
- 使用云服务器实现Google搜索
>>>>>>>>>>>>>>>>>>>>>>>>> ...
- google 搜索关键字技巧
google 搜索关键字技巧 来源 https://www.cnblogs.com/qiudabai/articles/9143328.html inurl: 用于搜索网页上包含的URL. 这个语法 ...
- google搜索小技巧
google搜索小技巧 一.总结 一句话总结:But most people may not be using Google search to its full potential.Want to ...
- 运营站点-开放robots后,站内google搜索数量第二天10条左右,第5天搜录9920条,可喜可贺
开放robots后,站内google搜索数量第二天10条左右,第5天搜录9920条,可喜可贺 2014年4月29日 16:17:56 到目前为之已搜录14000多条,已有客户在网站注册,加入购物车
随机推荐
- JS,复习
按钮,倒数五秒操作练习 <input type="button" id="btn1" value="按钮(5)" disable=&q ...
- http://blog.csdn.net/shawnkong/article/details/52045894
http://blog.csdn.net/shawnkong/article/details/52045894
- netstat命令
netstat命令会罗列出当前所有的网络连接.连接统计以及路由表信息.默认情况下,netstat命令将罗列出本地计算机所有开启的端口情况,以及它所连接的外部计算机情况. 端口就像一所房子的房门一样.数 ...
- NTFS u盘支持 - centos6
uname -r bash-4.1# uname -r2.6.32-431.el6.x86_64 ---- http://repository.it4i.cz/mirrors/repoforge/re ...
- RX(Reactive Extinsion)和IX(Interactive Extinsion)库改名了
RX和IX库是我经常用到的库,今天写一个小程序的时候想用IX库的时候,发现却找不到了.在它的源码的网站上找了一下,发现它们被改名了,具体的变化为为: 对于RX库: Rx-Main -> Syst ...
- centos7.2环境elasticsearch-5.0.1+kibana-5.0.1+zookeeper3.4.6+kafka_2.9.2-0.8.2.1部署详解
centos7.2环境elasticsearch-5.0.1+kibana-5.0.1+zookeeper3.4.6+kafka_2.9.2-0.8.2.1部署详解 环境准备: 操作系统:centos ...
- VUE 入门基础(4)
四,计算属性 基础例子 <div id='example'> <p>0riginal message: "{{message}}"</p> &l ...
- faster-rcnn(testing): ubuntu14.04+caffe+cuda7.5+cudnn5.1.3+opencv3.0+matlabR2014a环境搭建记录
python版本的faster-rcnn见我的另一篇博客: py-faster-rcnn(running the demo): ubuntu14.04+caffe+cuda7.5+cudnn5.1.3 ...
- Windows2008 R2 Enterprise离线安装IE10和VS2015过程记录
直接下载IE10,进行安装,提示需要联机下载更新: 在网上搜索到一篇文章(http://www.cnblogs.com/nbpowerboy/p/3383992.html),参考 以下载简体中文的Wi ...
- (转载)iOS 极光推送SDK 集成指南
iOS SDK 集成指南 使用提示 本文匹配的 SDK版本:r1.2.5 以后. 查看最近更新了解最新的SDK更新情况. 产品功能说明 极光推送(JPush)是一个端到端的推送服务,使得服务器端消息能 ...