admin管理员组

文章数量:1530516

2023年12月14日发(作者:)

ajax search功能参考:/search?t=thread&q=ajax%20search

/intl/zh-CN/apis/loader/

/intl/zh-CN/apis/websearch/docs/

AJAX Search API

一简单的Google API搜索例子

首先看一个Java代码的例子

需要两个jar的支持

view plaincopy to clipboardprint?

import ortedEncodingException;

import oder;

import tHttpMethodRetryHandler;

import ient;

import atus;

import hod;

import thodParams;

import ray;

import ject;

public class GoogleQuery {

public GoogleQuery() throws UnsupportedEncodingException {

String query = ("AOP示例+site:/zhjb1025", "UTF-8");//站内搜索

//String query = ("AOP示例", "UTF-8");

for (int i = 0; i < 3; i++) {

makeQuery("/ajax/services/search/web?start="

+ i * 8 + "&rsz=large&v=1.0&q=" + query);

}

}

private void makeQuery(String query) {

try {

HttpClient httpClient = new HttpClient();

GetMethod getMethod = new GetMethod(query);

eMethod(getMethod);

ams().setParameter(_HANDLER,

new DefaultHttpMethodRetryHandler());

int statusCode = eMethod(getMethod);

if (statusCode != _OK) {

n("Method failed: "

+ tusLine());

}

byte[] responseBody = ponseBody();

String response = new String(responseBody, "UTF-8");

JSONObject json = new JSONObject(response);

n("Total results = "

+ NObject("responseData")

.getJSONObject("cursor").getString(

"estimatedResultCount"));

JSONArray ja = NObject("responseData").getJSONArray(

"results");

n(" Results:");

for (int i = 0; i < (); i++) {

JSONObject j = NObject(i);

n(ing("titleNoFormatting"));

n(ing("url"));

n(("content"));

}

} catch (Exception e) {

n("Something ");

tackTrace();

}

n("--------------------------------------------");

}

public static void main(String args[]) {

try {

new GoogleQuery();

} catch (UnsupportedEncodingException e) {

tackTrace();

}

}

}

再来一个js的例子

view plaincopy to clipboardprint?

My Google AJAX Search API Application

补充:

有问题的小程序,可以参考:“google搜出来的结果远不是4个,但为什么我用firebug调试的时候发现的值为4呢?”

function searchComplete(searchControl, searcher) {

for (var i=0; i < ; i++) {

// Do whatever you want with the results

}

}

function OnLoad() {

var searchControl = new Control();

var webSearch = new rch();

rcher(webSearch);

(mentById("searchcontrol"));

rchCompleteCallback(this, searchComplete);

e('Google')

}

oadCallback(OnLoad);

jquery google API AjaxAPI 库

调用Google API的代码库,可以有效的减少自己站上的流量。比如Jquery,gzip后有19K,调用Google Api,不仅省去了流量,如果大家的网站都这么做的话,由于缓存原因,很多网站用到的话,就不需要重复加载了,非常节省资源,和加载时间。

采用Ajax动态加载google的API中jquery库的代码是这样的:

view plaincopy to clipboardprint?

1.

2.

之所以采用(这里也可以更换成其他域名如,之类的)是因为有时会不稳定,就会导致加载此代码的页面打不开。实际上如果你只用到jquery的话,根据firebug(火狐下插件)给出的实际地址,也可以直接向下面这样引入jquery库。

view plaincopy to clipboardprint?

1.

希望对需要的朋友有用。:)

引自/blog/the-introduction-of-google-ajax-apis-jquery-library-1682/

*使用 Google Ajax Search API 的准备工作/130739/20714

使用Google Ajax Search API/264790/94839

一个博客的例子/wmqxyh/blog/item/ 有一些检索的知识

*此API如何使用/blog/359893

IntelliJIDEA开发平台, name: Daniel ; key: 22457-MWPIW-INDLX-2PU2X-WBHSX-C4YK0

掌握 Ajax,第 10 部分: 使用 JSON 进行数据传输/developerworks/cn/web/wa-ajaxintro10/

*Ajax早期讲解06年,很全/developerworks/cn/web/wa-ajaxintro/

一个此API的详细讲解/2008/0806/

Sign-up for an API Key

Thanks for Signing up for a Google API key!

Your key is:

ABQIAAAA6mcpLt_42oc9byaXDAEQ4RT1xtEyFQOWuDnRzwI0AEsLsT5oSxRef5xHJc6ynRfHTZtAuNw5zuUM9Q

This key is good for all URLs in this directory:

/

Here is an example web page to get you started:

My Google API Application

Check out the API documentation for more information.

本文标签: 加载流量需要网站使用