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?
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:
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:
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:
That works! But I’m curious, so my last hack attempt is to simply remove the “source=” parameter entirely, producing the even shorter URL:
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:
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!