Reading from the question-URL: 36 bytes
’ƒËŠˆ.‚‹º.ŒŒ/q/’žYì•3X&•«.w'އ¡1èþ¨
-6 bytes thanks to @CommandMaster, by reading from this question's URL instead of the API
No direct TIO, since the .w
builtin (to access a website) is disabled on TIO. But:
’ƒËŠˆ.‚‹º.ŒŒ/q/’žYì•3X&•«
Try this part online to see the generation of the URL.
'އ¡1èþ¨
Try this part online to see the extraction of the amount of views from the HTML content. (Input doesn't contain the entire HTML content, because the TIO URL would extend 65k+ characters and be too big to post, haha.. xD)
Reading from the API: 46 42 bytes
•3X&•’¸¸.‚‹º.ŒŒ/…é/ÿ?€¼=ƒËŠˆ’žYì.w'š‹¡Åsþ
No direct TIO, since the .w
builtin (to access a website) is disabled on TIO. But:
•3X&•’¸¸.‚‹º.ŒŒ/…é/ÿ?€¼=ƒËŠˆ’žYì
Try this part online to see the generation of the API-URL.
'š‹¡Åsþ
Try this part online to see the extraction of the amount of views from the JSON.
Explanation:
’ƒËŠˆ.‚‹º.ŒŒ/q/’
# Push dictionary string "codegolf.stackexchange.com/q/"
žY # Push builtin "https://"
ì # And prepend it in front of the url
•3X&• # Push compressed integer 203590 (the id of this question)
« # Append it to the url
.w # Access this URL and read its contents
'އ '# Push dictionary string "wed"
¡ # Split the HTML on this word
1è # Get the second item (at index 1)
# (i.e. ` 119 times">\n <span class="fc-light mr2">Vie`)
þ # Only leave the digits (i.e. 1992)
¨ # And remove the last digit (2), that was part of the class
# (after which it is output implicitly as result)
•3X&• # Push compressed integer 203590 (the id of this question)
’¸¸.‚‹º.ŒŒ/…é/ÿ?€¼=ƒËŠˆ’
# Push dictionary string "api.stackexchange.com/questions/ÿ?site=codegolf",
# where the `ÿ` is automatically filled with this integer
žY # Push builtin "https://"
ì # And prepend it in front of the url
.w # Access this URL and read its contents
'š‹ '# Push dictionary string "count"
¡ # Split the JSON on this word:
# (i.e. `...,"view_count":14,"answer_count":2,...` will be split to
# [`...,"view_`, `":14,"answer_`, `":2,...`])
Ås # Pop and only leave the middle item (i.e. `":14,"answer_`)
þ # Pop and only leave its digits (i.e. 14)
# (after which it is output implicitly as result)
See this 05AB1E tip of mine (sections How to use the dictionary? and How to compress large integers?) to understand why ’ƒËŠˆ.‚‹º.ŒŒ/q/’
is "codegolf.stackexchange.com/q/"
; •3X&•
is 203590
; 'އ
is "wed"
; ’¸¸.‚‹º.ŒŒ/…é/ÿ?€¼=ƒËŠˆ’
is "api.stackexchange.com/questions/ÿ?site=codegolf"
; and 'š‹
is "count"
.