# 10 Clickbaits you can't resist

Write a program/function/script that takes a natural number i from 1 to 10 as input and outputs the URL of the Question with the i th hottest question on the Code Golf Portal

The ordering should be like in https://codegolf.stackexchange.com/?tab=hot. For example:
input 1
(at the point of this edit)

There are no strong restrictions to the output, as long as the url can be reasonably retrieved. Valid outputs include strings, console printing etc.

It's Code Golf, so shortest code in Bytes wins.

## Notes

If your program automatically opens a browser with the webpage, it counts as valid output and is totally cool.

If your program does not retrieve the ranking from current information (i.e. hardcoding the links), it is not valid.

The contest ends with the end of June.

As questioned: The indexing must be 1 based, ie: the input 1 must return the the first site of the hottest questions.

### Comment

I hope this question is not too clickbaity, as the stack exchange editor program was mocking me for the title. Originally I planned this challenge with Youtube trends, where it would haven been more fitting.

• Re: Stack Exchange mocking you for the question title, it's just triggering on the word you specifically. The assumption made by the software is that if you're asking people what they specifically think about something, then the question is probably going to be closed as primarily opinion-based (as if the question were factually-based, it wouldn't matter who you asked). Of course, this simple heuristic has a lot of false positives. – user62131 Jun 18 '17 at 1:57
• I'm surprised the answers aren't using URL shorteners: v.ht/b6QI – Engineer Toast Jun 19 '17 at 13:05
• @EngineerToast They're not usually allowed. – Esolanging Fruit Sep 20 '17 at 18:24
• @Challenger5 Indeed. I should probably re-read that list... – Engineer Toast Sep 20 '17 at 19:09

# PowerShell v5, 83 Bytes

(irm api.stackexchange.com/questions?sort=hot&site=codegolf).Items["$args"-1].Link  irm is short for Invoke-RestMethod which auto-parses the Json, makes life quite easy. add four bytes (saps for start-process) for version which opens in browser. saps(irm api.stackexchange.com/questions?sort=hot&site=codegolf).Items["$args"-1].Link


# Python + requests, 128 bytes

from requests import*


# Mathematica, 125 bytes

b="http://codegolf.stackexchange.com";b<>"/q/"<>StringCases[Import[b<>"?tab=hot","Text"],"ns/"~~a:DigitCharacter..:>a][[3#]]&


Anonymous function. Takes no input and returns a string as output. Was going to use the XML feed, but it seems to follow a different ordering than on the page.

# Python 2.7, 195 bytes

from urllib import*
import zlib, json


This is same answer by Dair, but using Python 2

• Welcome to PPCG! – Martin Ender Jun 18 '17 at 21:30

# Python 3, 221 bytes

from urllib.request import*
import zlib, json


Based off of ovs answer. Also, thanks to Oluwafemi Sule for helping me with an issue I had.

• Can you edit your answer and mention that it is Python 3? Thanks! :-) – Mauro Baraldi Jun 18 '17 at 20:28
• @MauroBaraldi Edited. Sorry about that. – Dair Jun 18 '17 at 20:29

# Stratos, 28 bytes

"-1"+
f"¹⁵s²&sort=hot"r"⁷s"@


Explanation:

"-1"+                    Decrement the input, and store it.
f"¹⁵s²&sort=hot"         Fetch the contents of the URL api.stackexchange.com/questions?site=codegolf&sort=hot.
r"⁷s"    Get the array named "items"


Try it!

# JavaScript (ES6), 106 bytes

Returns a Promise containing the JSON object for the desired question, which includes the link.

n=>fetch//api.stackexchange.com/questions?sort=hot&site=codegolf.then(r=>r.json()).then(j=>j.items[--n])

• Sacrificed 2 bytes allowing for 1-indexing.

# Try it

f=
n=>fetch//api.stackexchange.com/questions?sort=hot&site=codegolf.then(r=>r.json()).then(j=>j.items[--n])
oninput=_=>f(+i.value).then(console.log)
f(i.value=1).then(console.log)
<input id=i type=number>

• hm Im not sure at the moment how to handle 0 based indexing, but as the other answers appear to use 1 based indexing and it was specified that way, your answer is counted as 106 bytes (still current top score) – Moartem Jun 19 '17 at 9:34
• @Moartem: "Im not sure at the moment how to handle 0 based indexing" - Let me know when you've figured it out and I'll update my answer accordingly. I would suggest allowing for either 1-indexing or 0-indexing. – Shaggy Jun 19 '17 at 10:37
• I will fix it to 1-indexing, so all have the same prequesites, please update your answer. Anyway thanks for pointing this out. – Moartem Jun 19 '17 at 14:32
• @Moartem: Answer updated. For future reference, unless there's good reason not too, the norm is to allow solutions to use their language's default indexing. – Shaggy Jun 19 '17 at 17:11