16
3
Your task is to create a program which, given an input string, will output the first Google autocomplete result for that search. The format of input/output is up to you.
Rules
- Your program must take 1 input, a string, and output the top Google autocomplete/auto-fill suggestions result. The format of input/output is up to you. Just be sure to mention what your I/O format is.
- Obviously, accessing the Internet is allowed.
- URL shorteners (like bit.ly, TinyURL, etc.) are strictly disallowed. You should fetch your autocomplete results from this URL: http://suggestqueries.google.com/complete/search?client=your_browser&q=your_query or http://google.com/complete/search?client=your_browser&q=your_query. You are allowed to assume any browser name (or string, for that matter) for
client
. In the program I wrote, I assume Chrome. Any browser name or string should work. You are allowed to pass any options to the webpage as long as you are using some variant of http://suggestqueries.google.com/complete/search. - Please provide an explanation of how your program works. It is not mandatory, but I strongly advise it.
- All standard loopholes are strictly forbidden.
Test Cases
These are constantly changing, so edit this post if these become out-of-date.
'how to'
=> 'how to make slime'
'code golf'
=> 'code golf languages'
'you'
=> 'youtube'
'g'
=> 'google' (why would you google 'google'?)
This is code-golf, so may the shortest code win and the best programmer prosper...
3I would standardise a client name, to make it fair – Beta Decay – 2017-04-23T21:16:11.353
7Why the strict URL? As long as suggestqueries.google.com is used, without any URL shorteners, I don't see any problems. – Dennis – 2017-04-23T21:30:23.990
In particular, if we can use
output=toolbar
, we don't have to specify a client at all. – Dennis – 2017-04-23T21:36:10.893I don't think the strict url should be enforced. Banning URL shorteners should do the trick already. – Bald Bantha – 2017-04-23T21:40:09.860
Somewhat related (both involve parsing downloaded JSON objects) – Beta Decay – 2017-04-23T21:44:04.707
Nevermind,
output=toolbar
generates XML, the OP's URL doesn't. – Dennis – 2017-04-23T22:03:18.637@Dennis I did that because it was suggested that I have a standard URL for everyone to use (by @Riker). – ckjbgames – 2017-04-23T23:20:51.883
Well, I don't think it's a good idea. If a language can handle XML easier, why not let it use
output=toolbar
instead? There are other output methods that might also be interesting. – Dennis – 2017-04-23T23:29:09.057@Dennis Ok. I will change it where people will only have to use any URL from suggestqueries.google.com/complete/search. – ckjbgames – 2017-04-23T23:44:09.287
@Dennis Done! Now only requires that the URL http://suggestqueries.google.com/complete/search be used.
– ckjbgames – 2017-04-23T23:49:21.760@ckjbgames Why use suggestqueries?
https://www.google.com/complete
is working fine for me, too. – mınxomaτ – 2017-04-24T00:14:56.767@mınxomaτ It gives me a 404 Error when I try, but I'm glad it works for you. – ckjbgames – 2017-04-24T00:20:30.700
@ckjbgames Example:
https://www.google.com/complete/search?client=hp&q=a
. I'm just saying requiring that subdomain is not required. – mınxomaτ – 2017-04-24T00:21:23.673@mınxomaτ Oh. It does work. Cool! – ckjbgames – 2017-04-24T00:23:16.777
2@mınxomaτ but why not
https -> http
(save 1 byte), removewww.
(save 4 bytes),google.com -> google.us
(save 1 byte) or evengoogle.com -> g.cn
(save 6 bytes; i'm not sure why this still works, but it seems that it still working in 20170424) – tsh – 2017-04-24T01:23:31.5703Aren't search suggestions different for different users and regions? I don't think having standard test cases really works for this. – MrZander – 2017-04-24T15:53:10.140