24
1
I was messing around with Pyth's url request feature, and noticed that google always gave a response with a slightly different length for me, usually ~10500
characters.
So your task in this challenge is to print out the average length of the html response from http://google.com
.
Specs
- You will take an input
n
which is the number of requests to make. - For each request, you will make an HTTP get request.
- You will count the response body (the html text), not the headers.
- Output the arithmetic mean of the lengths of the responses.
- You can only access the url
http://google.com
, not any other. - This is code-golf, so shortest code in bytes wins!
Sample output for input 10
: 10560.1
(I used Python's urllib
for that)
P.S: does anyone know why google does this?
1Strange,
http://google.com
always returns 261 bytes for me...https://google.com/ncr
might return more though. – Neil – 2017-02-26T22:19:21.120@Neil Odd,
http://google.com
always returns 10422 bytes for me... – LegionMammal978 – 2017-02-26T23:40:44.717Can a ratio of integers (i.e., an exact fraction) be returned? – LegionMammal978 – 2017-02-26T23:43:21.963
@LegionMammal978 no, sorry. – Maltysen – 2017-02-27T00:34:57.557
5@Neil You get 261 bytes because you actually receive an URL redirection, code 302, which has in the body the new URL to follow. Some programs, like curl on linux, need a specific argument to follow that new URL automatically. – seshoumara – 2017-02-27T06:39:00.303
3@seshoumara TBH the challenge does not specify to follow redirections, so I would expect Neil's answer to be the correct answer by default, since it handles the actual HTTP response that
http://google.com
sends. Of course this isn't the point of the challenge, so the challenge should IMO be edited to reflect that. – Aaron – 2017-02-27T14:29:07.163@Aaron I agree, my comment above was more of an explanation to why he felt it was strange getting 261 bytes. I should have not mentioned the second part, but I was writing my own answer at that time with redirection, so I didn't realized it wasn't actually necessary. – seshoumara – 2017-02-27T14:34:27.710
Which average?` – theonlygusti – 2017-02-27T21:56:16.627
@theonlygusti the arithmtic mean – Maltysen – 2017-02-28T01:49:51.580