我想製作一個腳本,它在Google中搜索並顯示第一個相關圖像。來自Google的jQuery圖像建議
我的意思是,如果你輸入到輸入字段:汽車
if you search to word "car" via Google並建議第一圖象我。
您認爲有什麼方法可以做到這一點?
我想製作一個腳本,它在Google中搜索並顯示第一個相關圖像。來自Google的jQuery圖像建議
我的意思是,如果你輸入到輸入字段:汽車
if you search to word "car" via Google並建議第一圖象我。
您認爲有什麼方法可以做到這一點?
疑難雜症
<!--
copyright (c) 2009 Google inc.
You are free to copy and use this sample.
License can be found here: http://code.google.com/apis/ajaxsearch/faq/#license
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google AJAX Search API Sample</title>
<script src="http://www.google.com/jsapi?key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"></script>
<script type="text/javascript">
/*
* How to search for images and restrict them by size.
* This demo will also show how to use Raw Searchers, aka a searcher that is
* not attached to a SearchControl. Thus, we will handle and draw the results
* manually.
*/
google.load('search', '1');
function searchComplete(searcher) {
// Check that we got results
if (searcher.results && searcher.results.length > 0) {
// Grab our content div, clear it.
var contentDiv = document.getElementById('content');
contentDiv.innerHTML = '';
// Loop through our results, printing them to the page.
var results = searcher.results;
for (var i = 0; i < results.length; i++) {
// For each result write it's title and image to the screen
var result = results[i];
var imgContainer = document.createElement('div');
var title = document.createElement('h2');
// We use titleNoFormatting so that no HTML tags are left in the title
title.innerHTML = result.titleNoFormatting;
var newImg = document.createElement('img');
// There is also a result.url property which has the escaped version
newImg.src = result.tbUrl;
imgContainer.appendChild(title);
imgContainer.appendChild(newImg);
// Put our title + image in the content
contentDiv.appendChild(imgContainer);
}
}
}
function OnLoad() {
// Our ImageSearch instance.
var imageSearch = new google.search.ImageSearch();
// Restrict to extra large images only
imageSearch.setRestriction(google.search.ImageSearch.RESTRICT_IMAGESIZE,
google.search.ImageSearch.IMAGESIZE_MEDIUM);
// Here we set a callback so that anytime a search is executed, it will call
// the searchComplete function and pass it our ImageSearch searcher.
// When a search completes, our ImageSearch object is automatically
// populated with the results.
imageSearch.setSearchCompleteCallback(this, searchComplete, [imageSearch]);
// Find me a beautiful car.
imageSearch.execute("Subaru STI");
}
google.setOnLoadCallback(OnLoad);
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="content">Loading...</div>
</body>
</html>
parapapapa我們熱愛谷歌。
您需要無論是從谷歌一個JSON-P API,它提供的數據(我不相信他們提供一個),或寫你的服務器上運行,並查詢谷歌(服務器端腳本威力違反他們的服務條款,因此請在繼續之前檢查small print)。
更新:
5.3您同意不訪問(或試圖訪問)任何通過由谷歌提供的,除非你已經明確允許這樣做比通過接口以外的任何手段服務所以在與谷歌單獨的協議。您特別同意不通過任何自動方式(包括使用腳本或網絡抓取工具)訪問(或嘗試訪問)任何服務,並確保您遵守服務中存在的任何robots.txt文件中列出的說明。
您要做的是通過自動方式訪問數據,因此您將違反Google的服務條款。
是的,不是。 :)我給他們發了一條消息。我希望他們能給我一個。 (因爲我忠於Google):P – 2010-04-15 06:06:30
@Zoltan,@David,這是不正確的,這裏有一個API。看到我的答案。 – Aistina 2010-04-15 09:19:27
是有一個API ....檢查:
http://www.codeproject.com/KB/IP/google_image_search_api.aspx
你可以隨時玩: HTTP:// code.google.com/apis/ajax/playground/
/************************************************ ************************************************** ************************************************** ************************************************** ********************* 只要您特別允許您在與Google單獨簽署的協議中這樣做。 ************************************************* ************************************************** ************************************************** ************************************************** *****************/
這是一個違反了Google服務條款第5.3節的屏幕截圖工具。爲需要它的每個人提供 – Quentin 2010-04-15 09:51:59
是的,這是完全有可能使用Google AJAX Search API。
你的代碼會是這個樣子:
var imageSearch = new google.search.ImageSearch();
imageSearch.setSearchCompleteCallback(this, function(results) {
// figure out which picture from results you want
});
imageSearch.execute('car');
:) – 2010-04-16 05:14:16