Link to home
Start Free TrialLog in
Avatar of Grover McBroom
Grover McBroom

asked on

Get first image only on google image search

We use the following for the client to click to see images for the subject they have chosen. Works okay. I'd rather the display be in an iframe.

But the main problem is that we do not want to display all images, just 1 (or less than 5. ) Any based on the search criteria.  This should be done on the client side and be shown near the top of the resultant page.

Without getting into the Google Apps/API, and too technical, is there a simple way to ask Google to display only one or a few images, not the entire page? An entire page would simply be too much for the interface we prefer.
Here's what we're currently using.

 <a href="https://www.google.com/search?as_st=y&tbm=isch&as_q=&as_epq=<cfoutput>#UCASE(NewName)#</cfoutput>&as_oq=&as_eq=&cr=&as_sitesearch=&safe=active&tbs=isz:lt,islt:qsvga,itp:photo,ift:jpg&gws_rd=ssl" target="_blank"><cfoutput>#UCASE(NewName)#</cfoutput> IMAGES</a>
<hr />

Any suggestions?
Avatar of skij
skij
Flag of Canada image

Is there any reason why you have to use Google Search for this?  Why not Flickr?
ASKER CERTIFIED SOLUTION
Avatar of skij
skij
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Grover McBroom
Grover McBroom

ASKER

If this is server side, then Google may limit these sort of requests as there may be several hundred or more per day.

My knowledge and skill are both limited.  I assume this function is client side and that Google will see it as a client request???

I prefer Google because the search is for current news and current events, not general photos.

If this works as client side, this was an excellent solution, works great with ColdFusion.  In any event, it's great. Thank you! Helps lots.
The code provided is client-side, not server-side code. Google will see the request as coming from your visitors, not your server.   The quota is 10,000 queries per day per unique IP address, and because it is client-side code, the quota applies to your visitors, not your website.  Even if one of your visitors ran 10,000 queries in a day, your other visitors would not be affected.
That's  fantastic. Thanks again, great service, great knowledge.
Use simple_html_dom.php from http://simplehtmldom.sourceforge.net/ 
example:
include('simple_html_dom.php');
$search_keyword= $_GET['name'];
$search_keyword=str_replace(' ','+',$search_keyword);
$newhtml =file_get_html("https://www.google.com/search?q=".$search_keyword."&tbm=isch&gws_rd=cr&ei=16E0WMGSKYmisAHmp6b4Ag");
$result_image_source = $newhtml->find('img', 0)->src;
echo '<img src="'.$result_image_source.'"><br>';