来自 Google 的 jQuery 图像建议

发布于 2024-08-29 03:30:53 字数 233 浏览 9 评论 0原文

我想制作一个在 Google 中搜索并显示第一个相关图像的脚本。

我的意思是,如果您在输入字段中输入: car

如果您搜索单词“ car”通过 Google,它为我推荐了第一张图片。

您认为怎么样,有什么方法可以做到这一点吗?

I'd like to make a script which search in Google and shows the 1st relevant image.

I mean, if you type to the input field: car

if you search to word "car" via Google and it suggest the 1st image for me.

What do you think, are there any method to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

只有影子陪我不离不弃 2024-09-05 03:30:53

是的,使用 Google AJAX 搜索 API 完全可以做到这一点

你的代码看起来像这样:

var imageSearch = new google.search.ImageSearch();
imageSearch.setSearchCompleteCallback(this, function(results) {
  // figure out which picture from results you want
});
imageSearch.execute('car');

Yes, this is perfectly possible using the Google AJAX Search API.

You code would look something like this:

var imageSearch = new google.search.ImageSearch();
imageSearch.setSearchCompleteCallback(this, function(results) {
  // figure out which picture from results you want
});
imageSearch.execute('car');
情独悲 2024-09-05 03:30:53

您需要 Google 提供的 JSON-P API 来提供该数据(我不相信他们提供),或者编写一个在您的服务器上运行并查询 Google 的服务器端脚本(这可能 违反了他们的服务条款,因此请在继续操作之前检查小字) 。

更新:

5.3 您同意不通过 Google 提供的界面以外的任何方式访问(或尝试访问)任何服务,除非您在与 Google 签订的单独协议中获得明确允许。您明确同意不通过任何自动方式(包括使用脚本或网络爬虫)访问(或尝试访问)任何服务,并应确保您遵守服务上存在的任何 robots.txt 文件中规定的说明.

您要求做的是通过自动方式访问数据,因此您将违反 Google 服务条款。

You would need either a JSON-P API from Google that provides that data (and I don't believe they provide one) or to write a server side script that runs on your server and queries Google (which might be a violation of their Terms of Service, so check the small print before going any further).

Update:

5.3 You agree not to access (or attempt to access) any of the Services by any means other than through the interface that is provided by Google, unless you have been specifically allowed to do so in a separate agreement with Google. You specifically agree not to access (or attempt to access) any of the Services through any automated means (including use of scripts or web crawlers) and shall ensure that you comply with the instructions set out in any robots.txt file present on the Services.

What you are asking to do is accessing the data through automated means, so you would be violating the Google terms of service.

无戏配角 2024-09-05 03:30:53

是的,有一个 api...检查一下:

http://www.codeproject.com /KB/IP/google_image_search_api.aspx

您可以随时尝试:
http://code.google.com/apis/ajax/playground//************************************

​****************************************************** ****************************************************** ****************************************************** **************************************
只要您在与 Google 签订的单独协议中明确允许这样做即可。
****************************************************** ****************************************************** ****************************************************** ****************************************************** **************/

yes there's an api.... check this:

http://www.codeproject.com/KB/IP/google_image_search_api.aspx

you can always play around:
http :// code.google.com/apis/ajax/playground/

/***************************************************************************************************************************************************************************************************************************
As long as you have been specifically allowed to do so in a separate agreement with Google.
************************************************************************************************************************************************************************************************************************/

秋千易 2024-09-05 03:30:53

明白了,

<!--
  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>
​

帕拉帕帕帕,我们喜欢谷歌。

gotcha

<!--
  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 we love google.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文