ajax调用google API接口获取搜索结果.docx
《ajax调用google API接口获取搜索结果.docx》由会员分享,可在线阅读,更多相关《ajax调用google API接口获取搜索结果.docx(12页珍藏版)》请在三一办公上搜索。
1、ajax search 功能参考:httD:/AJAX Search API一简单的Google API搜索例子首先看- 一个Java代码的例子需要两个jar的支持commons-httpclient.jar commons-codec-1.3.jarview plaincopy t。clipboardprint?import java.io.UnsupportedEncodingException;import .URLEncoder;import mons.httpcIient.DefaultHttpMethodRetryHandler;import mons.httpcIient.Htt
2、pCIient;import mons.httpclient. HttpStatus;import mons.httpclient.methods.GetMethod;import mons.httpclient.pa rams. HttpMethodParams;import org.json.JSONArray;import org.json.JSONObject;public class GoogleQuery (public GoogleQuery() throws UnsupportedEncodingException String query = URLEncoder.encod
3、e(AOP 示例+site: UTF-8);/站内搜索 /String query = URLEncoder.encode(AOP 示例,UTF-8);for (int i = 0; i 3; i+) makeQuery(+ i * 8 + &rsz=large&v=1.0&q= + query);private void makeQuery(String query) try HttpClient httpClient = new HttpClient();GetMethod getMethod = new GetMethod(query);httpClient.executeMethod(
4、getMethod);getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler();int statusCode = httpClient.executeMethod(getMethod);if (statusCode != HttpStatus.SC_OK) System.err.println(Method failed:+ getMethod.getStatusLine();byte responseBody = getMethod.getRes
5、ponseBody();String response = new String(responseBody, UTF-8);JSONObject json = new JSONObject(response);System.out.println(Total results =+ json.getJSONObject(responseData).getJSONObject(cursor).getString(estimatedResultCount);JSONArray ja = json.getJSONObject(responseData).getJSONArray( results);S
6、ystem.out.println( Results:);for (int i = 0; i ja.length(); i+) (JSONObject j = ja.getJSONObject(i);System.out.printing.getString(titleNoFormatting);System.out.printing.getStringCurl);System.out.printing.get(content); catch (Exception e) (System.err.println(Something went wrong.);e.printStackTrace()
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ajax调用google API接口获取搜索结果 ajax 调用 google API 接口 获取 搜索 结果

链接地址:https://www.31ppt.com/p-4882816.html