Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 499
  • Last Modified:

Google image search "automation"

Hi Experts,

I'm looking for input how to retrieve the top 1 image from a Google Image search.

The case study is this - a user enteres details for a vehicle, the manufacturer and model - then the webpage should display a image of the vehicle model. (actually the user enters the license plate, then a webservice retrieves the manufacturer + model - we'd like to show how the should loook like)

Any examples or ideas ?
1 Solution

Code update :
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Search API Sample</title>
    <script src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      google.load('search', '1');

      var imageSearch;
	  var nb = 1;

      function searchComplete() {

        // Check that we got results
        if (imageSearch.results && imageSearch.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 = imageSearch.results;
          for (var i = 0; i < nb; 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('div');
            // 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

            // Put our title + image in the content

          // Now add links to additional pages of search results.

      function searchOnClick() {
        // Create an Image Search instance.
        imageSearch = new google.search.ImageSearch();

        // Set searchComplete as the callback function when a search is 
        // complete.  The imageSearch object will have results in it.
        imageSearch.setSearchCompleteCallback(this, searchComplete, null);

        // Find me a beautiful car.
		var s = document.getElementById("terms").value;
        // Include the required Google branding

  <body style="font-family: Arial;border: 0 none;">
  	<input type="text" value="Subaru STI" id="terms" ><input type="button" value="search" onClick="searchOnClick();" />
    <div id="branding"  style="float: left;"></div><br />
    <div id="content"></div>

Open in new window

internetservice_dkAuthor Commented:
Perfect - couldnt google that up my self ;)

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now