Industry guru Dave Taylor offers tech support on technical and business topics, including iPhone, iPod, Microsoft Windows, Sony PSP, cellphones, online advertising, CSS, Web design, business, Unix, Linux, SEO, Mac OS X, and shell script programming.     


How to Create Predefined Google Image Search Links?

Thanks for the Amazon URL [see Creating Amazon Search Links]. That worked beautifully. In fact, I sent you $5.00 for coffee in thanks. Do you have a similar answer for accessing Google Images via their URL?


Dave's Answer:

First off, thanks for the cup of coffee. I'm drinking it now as I type in this answer, actually, an almond milk chai from one of my favorite local coffee shops, Atlas Purveyors. Goodness, for sure.

In terms of what you ask, it's actually pretty easy to reverse engineer just about any search site because they use what's called a "GET method" of sending the search parameter to the system after you type in what you seek. That's really what I tapped into on the Amazon search links that you have already read.

I've already written about Google Image Search more than once here, but I've never considered the question of building pre-defined searches as simple text links. Still, easily done, and the place to start is to read my previous article on adding a Google Image Search box to your page.

Armed with that information, let's jump in!

Go to Google Image Search and search for, say, "Michelle Obama". Your search results link in your browser will look like this:

google

Ugh, that's really ugly, with lots going on. But, hmmm... what if I just deleted everything from the URL other than the q="michelle+obama", so the URL looks like this:

http://www.google.com/search?q="michelle+obama"

This sort of live URL hacking is essential to these sort of reverse engineering tasks, and this particular one reveals that, well, this isn't sufficient for the URL to work: the results are a regular Google search, not an image search. Conclusion: one of the missing parameters tells Google that you're doing an image search, not a regular one, and we need to restore it for the link to work.

Again, I'll edit directly in the Web browser address bar, reducing the search down to the pattern plus the two parameters that seem to be related to the type of search:

google

That works! But I'm curious, so my last hack attempt is to simply remove the "source=" parameter entirely, producing the even shorter URL:

google

Not sure what "tbm" stands for, but that's the key attribute, and if you give it the value "isch" (image search, no doubt) the link will work fine.

Now to build the search pattern itself. If it's just a word or couple of words, that's easy, simply replace "michelle+obama" with what you'd like to specify. If it's a more complex search with punctuation marks or other odd characters, my recommendation would be to actually do a search, then look closely at the resultant URL to see how the punctuation (etc) has been encoded.

Then you can do things like this: Look for images of disgraced pro biker Lance Armstrong or, better yet, images of news about Lance Armstrong that doesn't mention doping.

How did I do those? Pretty straightforward, here's the HTML for those:

Then you can do things like this: Look for images of disgraced pro biker <a href="http://www.google.com/search?q=lance+armstrong&tbm=isch" target="_blank">Lance Armstrong</a> or, better yet, images of <a href="http://www.google.com/search?q=%22lance+armstrong%22+news+-doping&tbm=isch" target="_blank">news about Lance Armstrong that doesn't mention doping</a>.

The only subtlety is that since I'm quoting the URL for properly formed HTML, I can't just use double quotes within the URL itself. Easy enough, simple replace each embedded " symbol with a %22. Easy.

Hope you find this helpful and sufficiently informative to get you started!


More Useful HTML, JavaScript and Web Site Programming Articles:
✔   How to Create Predefined Google Image Search Links?
Thanks for the Amazon URL [see Creating Amazon Search Links]. That worked beautifully. In fact, I sent you $5.00 for coffee in thanks....
✔   Can I embed a Facebook search box on my blog site?
I've seen your articles about how to add a Twitter or Google search box on a Web page, but I have a tougher...
✔   Can I use CSS for drop shadows on my blog?
I want to give my site a bit of a facelift and add some neat graphical elements. One of which is drop shadows....
✔   How can I embed interactive photo panoramas on my site/blog?
I read through your blog entry about how to take panoramic photos with iOS 6 and an iPhone 5 and got enthused. I've...
✔   How can I create a Twitter search URL shortcut?
I'd like to add a few Twitter search links to my Web site. Is that possible, or does Twitter prohibit this sort of...

Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
    Enter your name: and your email addr:  





Categorized: HTML, JavaScript and Web Site Programming   (Article 10683, Written by )
Tagged: google hacking, google image search, hacking google image search, html hacking, reverse engineer google
Previous: How to get started with Reeder Mac RSS reader?
Next: What are the new Windows 8 keyboard shortcuts?




Reader Comments To Date:

Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!
Rather amazingly, there are no comments on this article yet.

I do have a comment, now that you mention it!











I will never send you any unsolicited email. Ever.






Check This Out Too...

 
Look for Answers
Need Help? Ask Dave Taylor!


Follow Me on Pinterest

Find Me on Google+
ADT on G+
© 2002 - 2013 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. My lawyer says "Thanks".
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.