Google image search "automation"

Posted on 2012-09-04
Last Modified: 2012-09-05
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 ?
Question by:internetservice_dk
    LVL 81

    Accepted Solution


    Code update :
    <!DOCTYPE html>
    <html xmlns="">
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title>Google Search API Sample</title>
        <script src=""></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;
            // 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


    Author Closing Comment

    Perfect - couldnt google that up my self ;)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now