6
2
Challenge
Write a program which takes the URL of a PPCG answer as input and outputs the length of the answer's first code block in bytes.
Code Blocks
There are three different ways of formatting code blocks:
Four spaces before the code (-
represents a space, here)
----Code goes here
Surrounding the code in <pre>
tags:
<pre>Code goes here</pre>
or:
<pre>
Code goes here
</pre>
Surrounding the code in <pre><code>
tags (in that order):
<pre><code>Code goes here</code></pre>
Rules
You should only use the first code block in answer. Assume that the supplied answer will always have a code block.
You must find the length of the answer in bytes, not any other metric such as characters.
Solutions using the Stack Exchange Data Explorer or the Stack Exchange API are allowed. URL shorteners are disallowed.
Assume all programs use UTF-8 encoding.
Examples
Input: https://codegolf.stackexchange.com/a/91904/30525
Output: 34
Input: https://codegolf.stackexchange.com/a/91693/30525
Output: 195
Input: https://codegolf.stackexchange.com/a/80691/30525
Output: 61
Note: Despite what the answer may say, due to APL using a different encoding, 33 bytes isn't its UTF-8 byte count
Winning
The shortest code in bytes wins.
So no scraping the header? – Blue – 2016-09-01T22:04:35.573
@muddyfish Nope (note the third example) – Beta Decay – 2016-09-01T22:05:46.330
Some languages use a custom character encoding, different than UTF-8 (I'm pretty sure that's what happens in the APL answer). So the byte count depends on each language's default encoding. I think it may be better for the challenge to ask for character count rather than byte count – Luis Mendo – 2016-09-01T22:19:44.813
@LuisMendo I see, I'll specify UTF-8 then – Beta Decay – 2016-09-01T22:20:57.493
For example 2 I can only find 195 bytes. It looks like the 199 to 196 edit actually removed 4 bytes, not 3. Am I missing something? – milk – 2016-09-02T00:06:58.647
2Identation is meaningful in
<pre>
tags, and so are newlines in<code>
tags, so your Code goes here examples have three different lengths. If that's intentional, it should be mentioned. – Dennis – 2016-09-02T00:09:04.660@Dennis I've now removed the indentation – Beta Decay – 2016-09-02T05:26:59.580
But not the newlines. Both newlines in
<pre><code>\nCode goes here\n</code></pre>
count. However, they don't count in<pre>\nCode goes here\n</pre>
– Dennis – 2016-09-02T05:49:20.147@Dennis Oh, I didn't know that :P – Beta Decay – 2016-09-02T05:51:36.967