11
2
Found this picture on the web today. Being a lazy programmer, I don't want to actually open google and type a couple of characters. Way too much work! This is such an important task that it should be automated.
Challenge
Everyone knows that the first image in a google search result is always the best. Hence it should be presented to the user.
You are to write a program or function which takes a string as parameter and displays the first image it finds on google when you search for that name + the words glamour shot
behind it.
Google search queries
To search for images on google, the url should contain the query parameter tbm=isch
and q=query
, with query
being the name you want to search for.
A valid query string for my name Bas
would be www.google.com/search?tbm=isch&q=Bas
Input
Your program or function takes a single parameter of input, which is the name you want to search for on google. This string will consist of the characters [a-z]
, [A-Z]
, [0-9]
and (space). This string can be space seperated, to search for a space seperated string on google, one should replace the spaces with
+
. For example, this is a valid query:
www.google.com/search?tbm=isch&q=Bassdrop+Cumberwubwubwub+glamour+shot
Output
The image can either be drawn to the screen, or saved to a file (in any format).
If the first search result on google is a gif file, you can either show the gif or show any frame of that gif.
Test cases
Run this snippet to see the expected results
<pre>f('Bas') // www.google.com/search?tbm=isch&q=Bas+glamour+shot
<img src="http://i.stack.imgur.com/IViaM.jpg" style="width:40%;height:40%"/>
<pre>f('Bassdrop Cumberwubwubwub') // www.google.com/search?tbm=isch&q=Bassdrop+Cumberwubwubwub+glamour+shot
<img src="http://i.stack.imgur.com/tdhvW.png" style="width:40%;height:40%"/>
This is code-golf, shortest code in bytes wins!
What characters need to be supported in the input? Do we need to worry about URL encoding? – Martin Ender – 2016-10-04T10:09:44.283
@Martin Ender
[a-z0-9]
, edited my post. The urls will look like the examples I provided, no encoding needed, just space to+
– Bassdrop Cumberwubwubwub – 2016-10-04T10:13:09.797I guess,
A-Z
can also appear, judging by your example? – Martin Ender – 2016-10-04T10:55:12.637@MartinEnder Yes, it's case insensitive. Forgot to mention – Bassdrop Cumberwubwubwub – 2016-10-04T10:56:02.613
@BassdropCumberwubwubwub woops rookie mistake, I had indeed forgotten to escape the ampersand – Aaron – 2016-10-07T13:25:47.637
2There's a surprising number of people posing with guns when you play this game :D – Beta Decay – 2017-05-26T06:23:40.347
What exactly counts as being drawn to the screen? Would navigating to the source location in IE or Chrome count as being drawn to the screen? – Taylor Scott – 2017-05-30T17:41:46.973
Can I get the thumbnail of the image rather than the image itself? – BlackCap – 2017-05-30T21:59:14.137
it is good you included the
search queries
restricts, otherwise one could just set up a custom short-url website which takes care of it. – phil294 – 2017-06-03T04:13:09.957